2016-09-13 35 views
2

在我的應用程序,我有這樣的配置:如何在不同的端口運行節點應用程序 - 暫時?

module.exports = { 
    'port': process.env.PORT || 8080, 
    'database': 'mongodb://xxx:[email protected]:13456/practical', 
    'secret': 'ilovescotchscotchyscotchscotch' 
}; 

但目前,我想在不同的端口號上運行我的應用程序說,8081或別的東西。因爲我需要運行兩個配置爲相同方式的不同應用程序。

什麼是正確的方法? - 任何一個幫助我?

在此先感謝。

我想這個答案已經:How to change value of process.env.PORT in node.js?

但我得到這個錯誤:(我使用的Windows外殼)

C:\Tutorials\try\NodePractical\MEAN-Family> env:PORT = 1234 server.js 
env:PORT : The term 'env:PORT' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again. 
At line:1 char:1 
+ env:PORT = 1234 server.js 
+ ~~~~~~~~ 
    + CategoryInfo   : ObjectNotFound: (env:PORT:String) [], CommandNotFoundException 
    + FullyQualifiedErrorId : CommandNotFoundException 
+2

Duplicate http://stackoverflow.com/questions/13333221/how-to-change-value-of-process-env-port-in-node-js – Darkrum

+0

我試過所有,但沒有任何工作適合我。讓我發佈錯誤,我得到了什麼 – user2024080

回答

5

做這樣 如果你想從工藝接入端口varible。 env你必須使用這個命令來訪問。

PORT=8081 node server.js

。您正在使用錯誤的語法

相關問題