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

node-deployment

v1.0.1

Published

A nodeJS solution using Node clusters and Master-worker configuration to enable zero down time deployments

Downloads

8

Readme

node-deployment

Node deployment is a simplistic approach to using Node clusters and Master-worker configuration to enable zero down time deployments.

  • Closes the worker processes one by one and giving a timeout of 1 sec as a grace to HTTP server before it can close down on listening to new connections and thus complete/serve the existing connections.

It one by one replaces the new workers against the old ones(carrying the outdated code) and thus at the last all the new workers have the latest code.

Warning- This implementation while guaranteeing zero down time, at one point of time you may have two different pieces of code running

Getting Started

To install: npm install node-deployment

Usage

To use you may need to need to modify some of your existing code and wrap in into a function and then pass into handler as given below:

To create a general implementation, pass the following in the function which returns a server object:

let handler = require('node-deployment');

let initialiseServer = () => {
    var http = require('http');
    //You can either pass the function or Express instance in the create server instance
    let server = http.createServer((req, res) => {
        res.write('Hello client,wassup ?');
        res.end();
    });
    let port = 6971;
    server.listen(port);
    server.on('error', (error) => { console.log(error) });
    server.on('listening', () => { console.log(server.address()) });
    server.on('close', () => {
        console.log('Server is getting closed at ', new Date());
    });
    //Return server so that it can be used further by the handler, to close listening and give a grace time of 1 sec.
    return server;
}

//Now just pass the initialiseServer into the handler and let it do the magic for you :)
handler(initialiseServer);

Now when deploying code, just find the process id of the master process using:

ps aux|grep -i 'your custom filter using file name (may be)'

After having the master process id, just run the following command in the terminal,

kill -s SIGUSR1 <MASTER_PROCESS_ID>

This will send a user defined signal to the master process and it will initiate a restart of all workers one by one. SIGUSR1 is a user defined signal that can be given to a process.

 let envs = process.env;

Please make sure to have production mode on as envs.NODE_ENV==='production' or envs.ENABLE_WORKERS == 'true' should return true.

Acknowledgements

  • Hat tip to anyone who uses and contributes to the code....