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

autodeploy

v0.1.1

Published

Simple wrapper to make it easy to automatically deploy newer versions of your web apps

Downloads

2

Readme

autodeploy

Simple wrapper to make it easy to automatically deploy newer versions of your web apps

Installation

npm install --save autodeploy

What it Is

Autodeploy is a wrapper around node's core http module to make it easy to roll your own (for example) Git-based deployment.

Since many code-hosting sites offer hooks that they will make an HTTP request to when your code is changed, Autodeploy lets you set up a server on a different port that your code-hosting site can make requests to.

While automated deployment is great, there are some concerns that need to be addressed. For instance, there may be some times of day where you know that your app will be under high load. You wouldn't want to restart your server during those hours. Autodeploy provides a callback so you can decide if you want to restart your app. If the callback returns false, it will keep calling your callback at specified intervals, to make sure that the new code is eventually deployed.

Usage

require('autodeploy') returns a function that you call with options. That function then returns an instance of http.Server, which you can call listen on to start the server. While Autodeploy won't fall apart if you start multiple servers (as long as they are on different ports), this is not recommended.

Example:

// import autodeploy
var autodeploy = require('autodeploy');

// create the server
var server = autodeploy({
    // called to see if it's a good time to restart the server
    shouldRestart: function() {
        console.log('shouldRestart called');
        return Math.random() > 0.5;
    },

    // called when the app needs to restart
    restart: function() {
        console.log('restart called');
        // fetch new code
        // stop the app
        // install dependencies
        // start the app again
    },

    // specifies how often it should call shouldRestart if it returns false the first time
    interval: 5000,

    // path to listen on
    path: '/restart'
});

// start it!
server.listen(8000);
console.log('autodeploy listening at localhost:8000/restart');

Options

Options are passed in as an object, the only argument to Autodeploy's exported function.

shouldRestart

shouldRestart is called by Autodeploy the first time the request is made. It should return true if it's a good time to restart the app, false otherwise.

If it returns false the first time, Autodeploy will keep calling it at the interval specified.

Default: function() { return true; }

restart

restart is the function that Autodeploy calls to restart your app.

This option is required. Autodeploy will throw an error if it is not specified.

interval

The delay between subsequent calls to shouldRestart. This should be either a number of milliseconds or a string understandable by the ms module.

Default: 10000

path

The path that will restart your app.

Default: '/'

authorize

A function to authorize the request. This is meant to support systems like GitHub's Webhooks, where your app is given a secret that you specify as authorization. The function is passed the request object from node's http module as the only argument.

Default: function() { return true; }

License

Autodeploy is dual-licensed under the MIT and GPL 3.0 licenses. This means that you can use it in any package, no matter what license you are using.