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

pushtodeploy

v0.2.1

Published

the simple way to deploy an app

Downloads

55

Readme

pushtodeploy

pushtodeploy is a package which allows you to automatically deploy your Node.js application into your production or CI environment.

Email notified of a build failure

What does it do?

Builds a source copy:

  • It first runs git pull to get the latest changes on the server for the master (or other) branch.
  • It clones the entire repo into .pushtodeploy/<commit-hash>.
  • It copies the node_modules directory from the latest deployed version. This results in faster builds, but can be turned off if required.
  • Symlinks any secrets that are not in the repo into the build directory. Your production machine might contain a file--say, secrets.js--that contain API keys, etc. These will be copied in before the build is performed.

Builds the project and runs unit tests:

  • It simply calls npm install to install the package. Add stuff to your npm script to take control.
  • It runs npm test.

Deploys the build using symlink

  • It updates the .pushtodeploy/current symlink to point to .pushtodeploy/<commit-hash>.
  • It runs npm start. This is your npm script responsible for starting your server, for example. It should return a value, see below.

Can receive webhook events and send email updates

  • It can listen to Webhook events coming from your server (e.g. Bitbucket) which will fire off the automated deployment process.
  • It will send you an email for every failed and successful deployment.

How to use it

Firstly, install the package:

`npm install pushtodeploy --save`

Then create a pushtodeploy.json config file, which looks something like this (without the comments):

{
  "gitpull": {
    "enabled": true // true to git pull before build
  },
  "buildsrc": {
    "copyFromCurrent": [ // array of files to copy from the current build
      "node_modules"
    ],
    "secrets": [ // array of secrets that should be symlinked
      "../secrets.js"
    ]
  },
  "install": {},
  "tests": {},
  "switchbuild": {},
  "start": {},
  "cleanup": {
    "maxVersions": 5
  },
  "email": {
    "enabled": true, // true to send a success/failure email
    "from": "[email protected]",
    "to": "[email protected]",
    "smtp": {
      "host": "smtp.mandrillapp.com", // these options are passed to nodemailer.
      "port": 587,
      "auth": {
        "user": "[email protected]",
        "pass": "p@$$w0rd"
      }
    }
  }
}

Now, add

"deploy": "pushtodeploy --config pushtodeploy.json"

to package.json's scripts:

"scripts": {
  "deploy": "pushtodeploy --config pushtodeploy.json"
}

You will also need to have a start script. This shouldn't block (i.e. it shouldn't be node server.js). It should do something like start a server, or migrate a database, and then return. I recommend using PM2 to start the app. This is an example:

result=${PWD} && echo \"PWD: $result\" && cd .. && (pm2 reload testapp || pm2 start \"$result/server.js\" -i 4 --name testapp) && pm2 save

This script will change directory (there is a problem with symlinks resolving when inside), reload the application with no downtime (if it is already running) or start it if this the first time. It will also save the configuration.

Clone your repo onto your production server. Run

npm run deploy

More advanced stuff

Receiving Webhooks

Perhaps you want to be automatically deploy whenever your remote is pushed to. This can be achieved using webhooks -- setting up a server which you can POST to. Whenever the server receives an event, it will simply re-run npm deploy.

Firstly, create a new script called deploy-listen as follows:

"scripts": {
  "deploy-listen": "(pm2 stop deploylisten; pm2 start \"node_modules/.bin/pushtodeploy-listen --port 3123\" --name deploylisten) && pm2 save"
}

You can run this using npm run deploy-listen. Or, you can build your own server and call npm deploy according to some external stimulus.