opportunato
opportunato

Reputation: 447

Deployment of Node.js app to production

I am a front-end developer with experience in Ruby on Rails who is currently trying to build an Isomorphic App with React and Node.js. And I have a question about deploying such apps.

While I was developing Ruby applications, there always have been some scripts that would make the deployment process nice and easy — gathering new release from github, uploading it to new release folder, symlinking it to current, precompiling assets. Аnd I can't find something like this for Node.js straight away.

But I am sure that there must be. I am looking for the script that would setup the new virtual machine with all the packages, deploy it, and also would take care of the different environments and their configs (staging, for example). So, what is the idiomatic way to do it with Node.js?

Thanks!

Upvotes: 0

Views: 88

Answers (1)

Ruby on Rails has one methodology: rails. On the other hand, Ruby itself has a million methodologies because it's a general purposes programming language. Nodejs is the "Ruby" equivalent of "Ruby on Rails", it is very much not the "Rails" equivalent, and does not come with any one method for doing what you want. It has just as little to do with websites as Ruby, and is just a JavaScript interpreter with a general purpose API.

Only once you pick your "rails" equivalent web framework (like Express or Hapi, etc.) can you start asking about deployment scripts, and even then the answer is likely going to be "it's your code, just write your project-specific grunt or gulp or npm scripts tasks to do what you need". There are a ton of packages available for it to automate parts of what you want to do, so it's not as elaborate as "write the code from scratch" but it's also not as simple as "call this one single script". It's going to be the more traditional "chain these several utilities to perform each step, and if the entire chain succeeds, deployment has happened".

E.g.:

  1. check source code for errors
    1. check whatever CSS flavour we're using
    2. check JS
    3. check JSX if you're using React
    4. etc
  2. run all unit, perf, and interaction tests
  3. enforce code style
  4. create asset bundles in a dedicated "deploy" dir
    1. one css bundle
    2. one js bundle
    3. etc.
  5. sync "deploy" dir with your remote stage
  6. verify staging didn't blow up
  7. push staged copy over to production

None of this needs to be done in individual steps, but maybe you want them to be. Maybe there are steps missing that you'd like there to be, maybe you don't have a staging environment and only a production environment (a little iffy, but possible). Decide on the tasks that need to run, find the utilities that you do them, and then marry them together with your favourite task runner.

Upvotes: 1

Related Questions