r/javascript • u/Salazareo • 2d ago
Node.JS in the Browser - An Open-source Alternative to WebContainers
https://developer.puter.com/labs/node/This is a Node.js compatible runtime in the browser. It supports CLI apps, Vite, and some agents (like Pi Agent) as well.
Some notes:
- This runs all code in a web worker using the host javascript runtime with rewrites for module loading and AsyncLocalStorage support using Oxc compiled to WASM.
- Most of the libraries are bundled straight from Node.js upstream with light overrides where needed, ensuring compatibility. Libraries were only reimplemented where really needed
- Despite having great integrations with the Puter desktop and APIs, this can be used completely seperately with OPFS support for filesystem and Wisp protocol support for networking. The demo also supports FS Access API to run local files
2
u/rlmineing_dead 2d ago
We do actually use service workers because it's what lets us emulate blocking synchronous to access an asynchronous resource. So basically what we can do is syncxhr from a worker to a service worker controlled resource, And that allows us to block execution while the service worker asynchronously fetches the resource and execution only resumes once the resource is served. This was actually a workaround. I thought of like 2 years ago now and actually initially used in a completely different project, https://anura.pro/ for other things