2013-10-10 53 views
1

On Local Test it work。不同的端口(3001,8080)Node.js + Express只能在測試服務器上的端口3000上工作

但測試服務器上(天青)

對我同一臺機器上運行節點的App 2實例

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

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

但它的僅在端口3000上工作

如何將不同的端口設置爲Express App?

現在,我已經改變了在app.listen(3001)上的index.js,它不起作用。

在此先感謝。

回答

3

通常,雲平臺會設置一個環境變量,其中包含他們希望將您的應用程序粘貼到的端口。我沒有與任何Azure的經驗......在這裏看到了答案:How to run a node.js server on Azure?

具體做法是:在我的經驗

var port = process.env.port 

大多數雲供應商不會讓你在其他端口上玩。你總是可以指定一個本地主機端口也一樣,儘管這樣做的:

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

app.listen(port); 

這樣,如果process.env.port是不確定的(它會在你的開發環境),你退回到3001

合理?

相關問題