@fkn/vite-plugin
@fkn/vite-plugin is the one-line way to run Node-style code in the browser on FKN. It aliases the
Node builtins to the matching @fkn/lib entry points, so supported fs, net, dgram, and http
calls work in browser bundles. Storage uses FKN storage; networking uses the
cloud-backed socket APIs.
import { defineConfig } from 'vite'import { fkn } from '@fkn/vite-plugin'
export default defineConfig({ plugins: [fkn()],})With that in place, bare Node imports resolve to the platform:
import fs from 'fs'import net from 'net'
fs.writeFileSync('/save/state.json', JSON.stringify({ ok: true }))const socket = net.connect(443, 'example.com')What it wires
Section titled “What it wires”fsandfs/promisesto@fkn/lib/fsand@fkn/lib/fs/promises, the same implementation described by the Node fs polyfill guidenetto@fkn/lib/net, Node-compatible TCP over WebVPNdgramto@fkn/lib/dgram, Node-compatible UDP over WebVPNhttpto@fkn/lib/http, the HTTP client built on the socket layer
It matches the node: forms too (node:fs, node:net, node:dgram, node:http), and uses exact-match resolution
so a package like fs-extra is left alone. Every other Node builtin (stream, events, buffer, …)
falls back to node-stdlib-browser, and the plugin injects the Buffer / process / global shims
the polyfills expect.
Opting out
Section titled “Opting out”Each alias is on by default; pass false to drop one:
import { fkn } from '@fkn/vite-plugin'
fkn({ net: false, dgram: false, http: false }) // alias fs onlyThis lets libraries using the supported Node-compatible surface keep their existing imports. A BitTorrent engine like libtorrent-wasm opens net and dgram sockets through those imports, and the plugin routes them through FKN.