简体   繁体   中英

How can I run an independent express.js application using a 2nd node server?

I want to set up a second node.js server to run an express.js application which is an exact and independent copy of my current html (client-side) and js (server-side) files.

The reason is that I want to deploy my current code in a production environment that can be used by the team that will not be shut down, while I work on my current code in a development environment.

My worry is that I have added my current node.js server to my path and I am not sure if upon installation of the second node.js server my command to start the second server will interfere with the node.js server I have saved in my path variable.

Here are a couple of things to know before I ask my questions:

  1. I am working on a machine with a Linux distribution.
  2. I am using Express.js routing

I am using the instructions to install another instance of node.js and express.js at:

www.vultr.com/docs/installing-node-js-and-express

My questions are as follows:

  1. Is this as simple as installing node and express as per the instructions in the link above into a new directory and running from the new path without storing it in my path variable?
  2. Is there a better and more effective way to create a production and a development environment so that my team can use the app I have built without interfering with my current instance of node while ensuring 100% up time for the app deployed in production?
  3. Once the 2nd server is instantiated, how do I make the call from my terminal so that it does not turn on/off the original node server I have running from my path variable?
  4. Considering that the link above is a how to on how to install node and express from scratch and in Ubuntu (I am on CentOS - Gnome), is there a better "how to" that I should use to complete the second node and express install?
  5. When creating the new Port for the second node/express server to listen on can I just pick any number with 4 digits or is there a particular set of numbers that would be more effective to use? I am already using Port:3000 for my first instance in my development environment.

Thank you for your guidance.

Developing and serving from the same PC is not preferable, however, if you must, this is what you can do.

First, there is no need to install a second copy of node on to your machine - you can run multiple processes of node on the same machine without any problem. What I suggest you do is this:

  1. If you haven't already, commit your project into a git repository
  2. Create separate branches for development and production, as shown here: http://nvie.com/posts/a-successful-git-branching-model/#the-main-branches
  3. Every time you are ready to publish a new piece of code, push it to the master branch
  4. Move all configuration parameters to a config file, and create s separate one for dev/production, you can do this easily with the config package: https://www.npmjs.com/package/config
  5. Clone your repo to a separate folder which would always remain on the master (production) branch
  6. Run you server from that folder - your team could then connect to it
  7. All development would be done in the original folder. Once you are ready, push to master, and pull on the production folder.

Regarding the port numbers, you can use anything that is above 1024 and below 65535

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM