How do you get Node.js apps to production?

Aaron Powell on March 05, 2019

You've built a cool Node.js application and now it's time to get it into production. How do you go about it? πŸ€” What tools do you use to deploy?... [Read Full]
markdown guide
 

I have a discord bot that sits on Heroku.

  1. GitHub auto deploys to Heroku.
  2. Discord.js
  3. On my first deploy, took me over an hour to figure out that I need to disable NPM_CONFIG_PRODUCTION because Heroku was ignoring some essential dependencies. Very very counter-intuitive.
 

Heroku is slick, I've put so many apps on there, but have always struggled working out where to run unit tests (do I run it as part of the deployment or is that too late?). Are you deploying with the built-in hooks from Heroku or using a GitHub Action?

 

Built in hook. I don't have a test suite for this bot so i can't relate on that note πŸ˜†

Haha nothing like a yolo to production 🀣

I always wonder whether I still use Heroku because it’s still the best experience or because it’s just what I know best.

Little of column A, little of column B? πŸ˜‰

 

What helps me is having good reliable documentation. A painful deployment process (for a side project) is running into unknowns that sends you down a rabbit hole of searching error after error when all you wanted to do is make your app live. 😭 Documentation won't account for every little bug, but good docs from the tools you use are key.

 

I totally hear you on good documentation beign a life saver. I spent yesterday down a massive rabbit hole trying to work out why something was falling over only to find that there's a bug in the dependency I was using! 🀣

Is GitHub the first stop for you when looking for docs on a project?

 

I'd say the first step is usually searching moduleName docs. GitHub is most likely the first result though πŸ™ƒ

 

So True, Andy! Developers need good documentation to help keep projects healthy!

 

Zeit!

I'm still a beginner so I don't have great answers for the next couple questions. πŸ˜„

 

I've seen quite a few people talking about Zeit recently but I haven't had time to check it out. Given its traction it's getting higher up my TODO list though πŸ˜†

 

I usually deploy everything to Kubernetes using Helm. I love this pipeline as it remains the same as long as you can dockerize your application. Very easy to rollback and deploy to a brand new cluster. For automating the entire build process including tests and everything I use Codefresh / Google Cloud Build. I think the painful point is to maintain the Helm charts and the CI/CD configuration. I prefer to do more coding that to write charts and yamls

 

Kubernetes has been a total game changer on how to think about blue/green deployments. Are you running kubernetes locally for dev as well or only rolling it into containers for deployment?

 

Yeah Kubernetes totally changed my mind and workflow.
Locally I usually use docker compose for setting up databases and other requirements but the application runs locally

Are you using compose for Kubernetes or just compose to stand up containers?

 

I would add to this question, what about running node.js apps on premise? Many customers deploy locally in their intranet on Windows Server machines and I'm personally still unsure what's the best approach in those cases.

 

I used to use IBM Cloud (aka Bluemix) Pipelines. Due to a recent employer change I started using self hosted TFS with Build & Release pipelines.
All my Node applications live in Docker containers in a self hosted registry. And this is the most annoying part. Sometimes it takes up to 30 minutes to build, run tests (E2E&Unit) and deploy. But I think this relies on our self hosted infrastructure ;D Maybe I can try to convice my employer to switch to a cloud solution.

 

Are you doing multi-stage Docker files, or separate Docker files for each stage?

With regards to Cloud, it is just someone elses computer after all! πŸ˜‰

Jokes aside, do you know what the reason for choosing self-hosted infrastructure over cloud (public or private) is?

 

I usually use AWS's CI/CD tools. These include CodeCommit and CodePipeline.

Sometimes I just start up a lone EC2 instance for small applications.

 

Are you dropping them into containers on EC2 or just hosting with nginx/etc. in front?

 

I use Apache as a reverse proxy for Node.js

 

Webpack plugin that deploys during travis build. Travis has variables set for deployment. Works great.

Pain point for me as of this moment is lerna, symlinks all that madness.

 

Ha! I wrote an article just last week on deploying to npm! Still got to write the 2nd part about doing package versioning in releases.

Is your plugin an OSS one? Give it a shout-out! I'd be keen to see what you're doing with lerna, I tried it early on with a monorepo but it was really painful so we ditched it.

 

We're wrapping the aws-sdk in a custom webpack plugin. Travis fires the deploy npm script on every merge.

The issue with lerna is that we didn't put any effort into the integration, and not much team communication in the way of how we're using it. Right now, it's hoisting common dependencies and that's it. What it needs to be doing is narrowing scope to only changed packages (--since) and we need to implement publishing with it (right now everything is still published manually). We have the packages partially symlinked but changes to sub-packages aren't necessarily deployed so it's possible to get a deployment in a state where the application is in an irreconcilable version with an external application, which would be dependent on the published npm package.

code of conduct - report abuse