Running node.js
in production

Ken Perkins,
node.js developer advocate @ rackspace



Step 1


 > node app.js &




Questions?




OK

So what does in production even mean?




It's all about the setup.




Everything starts with
Configuration


If you setup dev the same way you setup prod
you're gonna have a good time.




What does that even mean?


Use puppet, chef, docker, etc. What you want is repeatable, deterministic infrastructure for every environment.



Node is great at high concurrency, but don't forget about OS tuning


fd limits, open sockets, etc



Now you need to
build & deploy


Git, rsync, grunt, ftp, etc.




    A word of caution about

    dependencies & npm:


    #1 Always use semver
    #2 npm deploys break often
    #3 checking in node_modules is mostly ok*


    * Native modules, pkg bloat can cause difficulties






     > npm publish --force



    What about npm shrinkwrap?

    No Checksum (--force fucks you)
    Still depends on moving parts (registry.npmjs.org)
    Lossy conversion (npm shrinkwrap > npm install > npm shrinkwrap yields different npm-shrinkwrap files)



    Running your app


    or

    > service your-app start



    Use process management

    for your OS


    upstart, runit, systemd, etc



    Turn your node app
    into a proper service


    Use tried & true tools that are designed
    for exactly what you need: to
    keep your process running.




    Now keep your app healthy

    Logging & monitoring can't be afterthoughts




    Great tools for logging

    Loggly, Papertrail, rsyslog, Winston, Airbrake, Concurix, etc


    Use multiple

    monitoring strategies


    Remote Ping Probes (i.e. pingdom)
    App/Svc Level Monitoring (i.e. get /api/service-ping === 200)
    Process Level Monitoring (i.e. service your-app status)
    System Level Monitoring (mem, cpu, swap, etc)
    & more...



    The point isn't just to prevent shit from breaking, it's also how do you deal with it when it does.



    The key takeaway is that running node in production is all about mitigating liabilities.




    fin



    @kenperkins (github/twitter)
    http://j.mp/node-in-prod

    Running node.js in production

    By Ken Perkins

    Running node.js in production

    Lets take a look at some of the key steps to setting up your environment to run node successfully in production.

    • 4,407