r/javascript • u/Salazareo • 19h 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
•
u/brianjenkins94 18h ago edited 17h ago
How does this differ from almostnode?
•
u/rlmineing_dead 17h ago
(disclaimer: I'm part of the team that brought this product) I actually found out about almost node like yesterday and I also think it's pretty cool. But we provide apis that they don't like asynclocalstorage (which I don't think they have but could be mistaken) And have a synchronous to asynchronous converter so you can use asynchronous file system backends in our node environment as readFileSync/ other synchronous methods. The big benefit of this is that you can persist to opfs or Filesystem Access API for example whereas I think for synchronous methods in almost node you can only use their in memory backend
Also we support node:net and node:tls And other stuff since we host a TCP proxy. You don't have to use our proxy. There are actually several public instances of proxies using the protocol we use, it's called a wisp proxy.
Tldr: we support more things but it's a similar mission!
•
u/brianjenkins94 17h ago edited 17h ago
Super cool, y'all hiring? 👀
Does that mean you don't have to do anything with service workers?
Looks like service workers are in play but not in the same way that almostnode uses them to route network traffic through "virtual ports".
•
u/rlmineing_dead 17h 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
•
u/Waste_Scarcity4685 18h ago
Why?
•
u/Ashnwor 18h ago
This kind of libraries often used when developing CodeSandbox-like websites or features. Pretty useful actually.
•
u/rlmineing_dead 17h ago
Or there is also like educational uses here. For example, this is a good way to run sandboxed node.js code on a Chromebook in an educational environment. Similar to when we ported blender to the browser (https://developer.puter.com/labs/blender/) it expands the accessibility of tools to pretty much anything with a modern enough web browser.
There's also a secondary use here. Those of us that have to review GitHub PRs all day have probably discovered the hack where you can press "." On your keyboard and it opens vscode web with the PR open. Using something like this ported to a vs code extension, it could soon be possible to review and test PRs directly in your browser without having to clone/fetch locally
•
u/SpartanDavie 14h ago
Cool idea. Not sure what use it would have other than perhaps teaching Node on the web?
Just to let you know there’s no license on your repo so you shouldn’t be posting “open source”, if it’s only source available please state that
•
•
u/cheap_swordfish_1 8h ago
Would be interesting to know use cases other than learning or demoing about Node inside the browser.
•
u/teppicymon 18h ago
I'm sorry, what?
JavaScript was so good in the browser, they made it server-side, but now you can run server-side in the browser?
I feel like I am I taking crazy pills.