1
votes

On Local Test it work. on different port (3001, 8080)

But on Test Server (Azure)

I run 2 instance of Node App on same machine

$ node api1/index.js (on port 3000)
$ node api2/index.js (on port 3001)

and

$ node api1/index.js (on port 3001)
$ node api2/index.js (on port 3000)

But it only works on port 3000.

How do I set different port in Express?

Now, I've changed at app.listen(3001) on index.js and it doesn't work.

1

1 Answers

5
votes

Often cloud platforms set an environment variable that contains the port they want you to stick your app on. I don't have any experience with Azure... See the answer here: How to run a node.js server on Azure?

Specifically:

var port = process.env.port

Most cloud providers in my experience don't let you play on other ports. You can always specify a localhost port too, though by doing this:

var port = process.env.port || 3001 //(or whatever)

app.listen(port);

this way if process.env.port is undefined (which it will be in your dev environment) you fallback to 3001.

Make sense?