简体   繁体   中英

Can I run 2 Node.js Project in windows?

Can I run 2 Node.js Project in windows?

If yes, How Can I do That?
If no, Can I run 2 Node.js Project in a dedicated Host?

You have a lot of options. If you want to have diffrent versions of nodeJS, for windows NVM-windows is the best option.

But instead if you're talking about running different http-request based programs, the simplest solution is to simply listen at different ports on each of the project on your system. Eg, if you're using nodejs http module

// project 1
server.listen('8080', (err) => { // Will start up the server on port 8080
  console.log(`server is listening on 8080`)
})

// project 2
server.listen('8081', (err) => { // Will start up the server on port 8081
  console.log(`server is listening on ${port}`)
})

or if you're using express server

// project 1
app.listen(3000, function() {
    console.log('app listening on port 3000 for project 1 !');
  })

// project 2
app.listen(3001, function() {
    console.log('app listening on port 3001 for project 2 !');
  })

NOTE: This requires that you switch to port 80 on server as that is the default port for request on any server.

If you'd want to get a more sophisticated solution wherein both these applications are sand-boxed into their own environment, you can go for Virtual box or Docker . Both of them offer same functionality but in different manner. They both can set up a isolated environment for your application so that you'r applications don't interact with each other. To give you a perspective of this, let's say your application uses a enviornment-variable that you have set to 'Abra-kadabra' for project 1. Now if you refrence that enviornment variable in project 2, you'd still get 'Abra-kadabra' while you might want second project to have the value 'whoosh' Virualbox or docker would set up a isolated system where in you can have this exact functionality available to you

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