4

I wanted to know standard process to deploy nodejs app on production. As of now I am following the process as below

Pull the source code

git pull git_url

Install npm dependencies

npm install 

Build the code

npm run build

run the application

nohup node server/index.js &

But I am thinking of pulling source code to prod is the totally wrong way. Please, someone, guide me the exact way to deploy node app on the production server. Also, any other way to run the app continuously as service. I am aware with pm2 module to run a process in the backend. If there is any other way to manage it properly.

3
  • "But I am thinking of pulling source code to prod is the totally wrong way" Why not, as long as you don't pull from a dev or unstable branch. In common branching strategies, master is considered as the "production ready" branch so you should pull from it and nothing else. Feb 12, 2019 at 11:36
  • On a differnt topic, are you deploying on a bare metal server, or in some virtual environent, container or VM? Feb 12, 2019 at 11:37
  • Thanks @SylvainLeroux. I am not sure about js exactly. But as in java we are creating artifact like .war . I thought with npm run build we are creating the same. ( as it is creating some build directory). Can you tell me is there anything like this in nodejs
    – Sunil Bhoi
    Feb 12, 2019 at 11:50

1 Answer 1

1

You could issue an npm pack which will create a tgz and then you could push it to an artifact manager like Nexus3. By doing this one uses the same approach as creating artifacts in Java like JARs and WARs. If you ensure that the artifacts cannot be overwritten, you specify a version and restrict publication to an artifact manager by the CI like jenkins then the artifacts are immutable and you are in control. E.g. if there is a bug in version X you could revert it to the previous version that was working well.

Note: if you are planning to use npm pack I would suggest to use an abbreviation like @angular does to ensure that there is a clear destinction between artifacts that were created by your company and libraries from npmjs.org. This could be done by adding an abbrevation of your company like @z to the package name. A name could look like: @z/some-package.

1
  • Great. Thanks for input.
    – Sunil Bhoi
    Dec 30, 2019 at 11:29

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.