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 🙏

© 2024 – Pkg Stats / Ryan Hefner

@lucidsoftware/nodegun

v0.4.12

Published

Node.js server supporting the Nailgun protocol

Downloads

7

Readme

Nodegun

Nailgun for Node.js

Purpose

Nodegun improve start up overhead for Node.js programs.

// helloworld.js
console.log('Hello world');
$ time node helloworld.js
Hello world
real    0m0.102s

$ time ng helloworld.js
Hello world
real    0m0.004s

Architecture

Nodegun is inspired by Nailgun, a system for reducing startup overhead of Java programs. Users invoke a small executable (written in C), which connects to a long-running JVM server where the work is actually performed.

Nodegun is a Node.js server implementation of the Nailgun protocol. Users connect with the same native client, which submits work to the server.

Nodegun can run either as a single process, as master-worker for parallelized workloads:

Getting started

  1. Install the nailgun client, either from source or from your package manager. E.g. for Ubuntu,
$ apt-get install nailgun
  1. Install and run nodegun.
$ npm install -g nodegun
$ nodegun
  1. Create a Node.JS program to run (aka a "nail").
// example_nail.js
console.log(process.argv.slice(2).join('-'));
  1. Run the client
$ ng example_nail The Fast and the Furious
$ # (or ng-nailgun ...)
The-Fast-and-the-Furious

Nails

Requirements

Most Node.JS programs should work as nails without modification. Nodegun adjusts the runtime environment, including

  • process.argv
  • process.env
  • process.exit
  • process.stdin, process.stdout, process.stderr

The most significant requirement: Nails must clean up after themselves. They must not corrupt state, create memory leaks, etc.

The root nail module and re-run each time. Modules required by the nail module are run only once. In both cases, code is cached via the standard require mechanism. The server must be restarted if nails are updated on disk.

Resolution

Nodegun resolves the requested nail

  1. As node would do, i.e. relative to the current directory.
  2. As require would do from nodegun process.

Concurrency

Each worker process (or the main process, if there are no workers) runs only one nail at a time.

Examples

Nodegun comes with a few built-in nails, including

  • ng ./examples/hello - Print Hello World
  • ng ./examples/info - Print arguments and working direcotry
  • ng ./examples/echo - Copy stdin to stdout

What is this good for?

We use Nodegun in our build system. A fast CLI to Node.js amenable to in concurrent, polyglot build systems.

In this way, it is similar to Nailgun, which is used in build tools like Buck and Pants.

Server options

usage: main.js [-h] [-v] [--tcp [TCP] | --local [LOCAL]]
               [--status-tcp TCP | --status-local LOCAL] [--workers [WORKERS]]
               

Node.js server that supports the Nailgun protocol.

Optional arguments:
  -h, --help            Show this help message and exit.
  -v, --version         Show program's version number and exit.
  --workers [WORKERS]   If present, number of worker processes to start. A 
                        flag with no argument starts one per CPU.

Transport:
  Transport and address. TCP is used by default.

  --tcp [TCP]           TCP address to listen to, given as ip, port, or 
                        ip:port. IP defaults to 0.0.0.0, and port defaults to 
                        2113.
  --local [LOCAL]       Local address to listen to. Defaults to /tmp/nodegun.
                        sock.

Status:
  Optionally expose internal status information via HTTP server.

  --status-tcp TCP      TCP address to listen to for status, given as ip, 
                        port, or ip:port. IP defaults to 0.0.0.0.
  --status-local LOCAL  Local address to listen to for status.