npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2025 – Pkg Stats / Ryan Hefner

@coder/node-browser

v1.0.8

Published

Use Node APIs in the browser.

Downloads

45

Readme

node-browser

This module provides a way for the browser to run Node modules like fs, net, etc.

Internals

Server-side proxies

The server-side proxies are regular classes that call native Node functions. The only thing special about them is that they must return promises and they must return serializable values.

The only exception to the promise rule are event-related methods such as onEvent and onDone (these are synchronous). The server will simply immediately bind and push all events it can to the client. It doesn't wait for the client to start listening. This prevents issues with the server not receiving the client's request to start listening in time.

However, there is a way to specify events that should not bind immediately and should wait for the client to request it, because some events (like data on a stream) cannot be bound immediately (because doing so changes how the stream behaves).

Client-side proxies

Client-side proxies are Proxy instances. They simply make remote calls for any method you call on it using a web socket. The only exception is for events. Each client proxy has a local emitter which it uses in place of a remote call (this allows the call to be completed synchronously on the client). Then when an event is received from the server, it gets emitted on that local emitter.

When an event is listened to, the proxy also notifies the server so it can start listening in case it isn't already (see the data example above). This only works for events that only fire after they are bound.

Client-side fills

The client-side fills implement the actual Node API and make calls to the server-side proxies using the client-side proxies.

When a proxy returns a proxy (for example fs.createWriteStream), that proxy is a promise (since communicating with the server is asynchronous). We have to return the fill from fs.createWriteStream synchronously, so that means the fill has to contain a proxy promise. To eliminate the need for calling then and to keep the code looking clean every time you use the proxy, the proxy is itself wrapped in another proxy which just calls the method after a then. This works since all the methods return promises (aside from the event methods, but those are not used by the fills directly—they are only used internally to forward events to the fill if it is an event emitter).