All Posts

Simple Node.js Production Setup

Right from your terminal – without a third partyservice

./deploy www.example.com

There are a lot of articles about how to setup Node.js in production, but they don’t always cover the full thing in an automated, easily deployable way. We will review how to setup a one-line Node.js deploy from your local terminal (OSX or Linux), with very minimalcode.

No fancy third party services deploy services here – just a little bash and an upstartscript.

Deploying Node via simple shellscript

The script belowwill:

ensure Node.js isinstalled

make an archive out of yourcode

upload it via ssh to theserver

log to a file and rotate the logs regularly to prevent filling up thedisk

setup auto-starting on serverreboot

setup auto-starting when the appcrashes

You can reuse the script again and again to deploy yourapp.

While this isn’t a silver bullet, it lets you host Node.js apps on an extremely cheap VPS (virtual private server), if you like, without needing too much knowledge of server admin. VPS hosting can be orders of magnitude cheaper than cloud hosting – and faster. You can host a simple Node.js website for a dollar or two per month in many cases – extremelycheap.

Configuration (upstart .conf file) for Node.js app on Ubuntu14.04

From inside your appdirectory:

touch myapp.conf # create it with your app name
chmod +x myapp.conf # make it executable