Answers: <p>You could issue an <code>npm pack</code> 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.</p>
  
  <p>Note: if you are planning to use <code>npm pack</code> I would suggest to use an abbreviation like <code>@angular</code> 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 <code>@z</code> to the package name. A name could look like: <code>@z/some-package</code>.</p>
  
Answers: CC BY-SA 4.0
Answers: 2019-12-30T11:29:38.613Z
Answers: Great. Thanks for input.
Answers: Sunil Bhoi
Answers: CC BY-SA 4.0
Answers: 2019-12-24T19:43:10.283Z
Answers: 2019-12-24T19:43:10.283Z
Answers: 030
Body: <p>I wanted to know standard process to deploy nodejs app on production. As of now I am following the process as below</p>
  
  <p>Pull the source code</p>
  
  <pre><code>git pull git_url
  </code></pre>
  
  <p>Install npm dependencies</p>
  
  <pre><code>npm install 
  </code></pre>
  
  <p>Build the code</p>
  
  <pre><code>npm run build
  </code></pre>
  
  <p>run the application</p>
  
  <pre><code>nohup node server/index.js &amp;
  </code></pre>
  
  <p>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.</p>
  
Comments: CC BY-SA 4.0
Comments: 2019-02-12T11:36:41.937Z
Comments: _"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](https://nvie.com/posts/a-successful-git-branching-model/), _master_ is considered as the "production ready" branch so you _should_ pull from it and nothing else.
Comments: Sylvain Leroux
Comments: CC BY-SA 4.0
Comments: 2019-02-12T11:37:47.507Z
Comments: On a differnt topic, are you deploying on a bare metal server, or in some virtual environent, container or VM?
Comments: Sylvain Leroux
Comments: CC BY-SA 4.0
Comments: 2019-02-12T11:50:52.637Z
Comments: 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
Comments: Sunil Bhoi
Tags: <cicd><github><node.js><artifacts>
Title: node js deployment on production server
UserDisplayName: Sunil Bhoi
ThreadText: # node js deployment on production server
  
  (Asked by: username_0 on 2019-02-12)
  
  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.
  
  **Tags:** cicd, github, node.js, artifacts
  
  > **Comments:**
  > **username_1**: _"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](https://nvie.com/posts/a-successful-git-branching-model/), _master_ is considered as the "production ready" branch so you _should_ pull from it and nothing else.  
  > **username_1**: On a differnt topic, are you deploying on a bare metal server, or in some virtual environent, container or VM?  
  > **username_0**: Thanks @username_1. 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  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_2 on 2019-12-24. Score: 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`.
  
  > **Comments:**
  > **username_0**: Great. Thanks for input.  
  
  ---
  
  