title: Prod and Dev environment in nodejs
body: <p>*** I am a beginner of nodejs, hope can give me some advice, thank you so much :)</p>
  
  <p>I have one server to run my nodejs application (REST API).</p>
  
  <p>My application have two environment (development and production),
  i update the code in development quite frequent to do testing,
  after i complete the development, i will release the code to production.</p>
  
  <p>I am using pm2 in nodejs to run the application.
  Here is the folder structure of my REST API</p>
  
  <ul>
  <li>restapi
  
  <ul>
  <li>app1</li>
  <li>node_modules</li>
  <li>db.js</li>
  <li>....
  index.js</li>
  </ul></li>
  </ul>
  
  <p>Here is my question:
  What is the best way to setup the dev and prod environment for my app?</p>
  
  <p>I have two idea
  <strong>Idea 1:</strong>
  Put prod and dev seperate to two folder, both listening to same port and run as single service
  prod: www.xxx.com:8080/app_dev/
  dev:  www.xxx.com:8080/app_prod/</p>
  
  <ul>
  <li>restapi
  
  <ul>
  <li>app_dev</li>
  <li>node_modules</li>
  <li>db.js</li>
  <li>....</li>
  <li>app_prod</li>
  <li>node_modules</li>
  <li>db.js</li>
  <li>....
  index.js</li>
  </ul></li>
  </ul>
  
  <p><strong>Idea 2:</strong>
  prod: www.xxx.com:8080/app/</p>
  
  <p>dev:  www.xxx.com:8081/app/</p>
  
  <p>Run as two services, listening to different port.</p>
  
  <p>In my server, i just need to seperate two folder:</p>
  
  <ul>
  <li><p>dev</p></li>
  <li><p>prod</p></li>
  </ul>
  
  <p>I can always change the code in dev and restart the app and never impact prod</p>