2.0.0-rc.8 • Published 9 months ago

nodesockd v2.0.0-rc.8

Weekly downloads
39
License
MIT
Repository
github
Last release
9 months ago

Nodesockd

This tool is the missing link between a Nginx reverse proxy and a Node.js backend service. Typically, setups like this bind the backend service to a port on the loopback interface, which is secure enough, but adds some overhead. There are some pitfalls to switching over to UNIX sockets though, and this package aims to address them in one fell swoop:

  • atomic deploy, even with database migrations
  • multiple workers supported
  • standby workers for fast failover

Installation

npm install --save nodesockd

Documentation

Quick start

Create a file called nodesockd.yaml in your application's root directory with the following contents:

# nodesockd.yaml
script: build/app.js  # the entrypoint of your app
tmpDir: tmp           # make sure this directory exists!

Next, in your app entrypoint, you'll need to do something like this:

// src/app.ts

import { nodesockd } from 'nodesockd';
import * as express from 'express';

const app = express();

// register routes etc.

const server = app.listen(nodesockd.socketPath ?? 1234, async () => {
  // tell Nodesockd that the worker is ready to start serving requests:
  await nodesockd.reportOnline();
});

nodesockd.on('shutdown', () => {
  // when Nodesockd tells the worker to shut down:
  server.close();
});

Now you can run your app like this:

# through Nodesockd - will listen on port 8000:
node_modules/.bin/nodesockd daemon --dev-server

# change the dev server listen port:
node_modules/.bin/nodesockd daemon --dev-server=8123

# without Nodesockd - will listen on the fallback port 1234
# defined in the app code:
node build/app.js

Of course, this is what you might use for local development; in production, you'll need to set some things up to correctly expose the application sockets to Nginx. Refer to the documentation for more details.

2.0.0-rc.6

9 months ago

2.0.0-rc.7

9 months ago

2.0.0-rc.8

9 months ago

2.0.0-rc.2

1 year ago

2.0.0-rc.3

1 year ago

2.0.0-rc.4

1 year ago

2.0.0-rc.5

1 year ago

2.0.0-rc.1

1 year ago

1.4.0

1 year ago

1.3.4

3 years ago

1.3.3

3 years ago

1.3.2

3 years ago

1.3.0

3 years ago

1.2.3

4 years ago

1.2.2

4 years ago

1.2.0

5 years ago

1.1.5

5 years ago

1.1.4

5 years ago

1.1.3

5 years ago

1.1.2

5 years ago

1.1.1

5 years ago

1.1.0

5 years ago

1.0.1

5 years ago

1.0.0

5 years ago