【问题标题】:How to run the node app in different port - as temporarily?如何在不同的端口运行节点应用程序 - 临时?
【发布时间】:2017-01-21 04:25:04
【问题描述】:

在我的应用中,我有这样的配置:

 module.exports = {
     'port': process.env.PORT || 8080,
     'database': 'mongodb://xxx:xxxx@ds013456.mlab.com:13456/practical',
     'secret': 'ilovescotchscotchyscotchscotch'
 };

但目前,我想以不同的端口号运行我的应用程序,例如 8081 或其他。因为我需要运行 2 个以相同方式配置的不同应用程序。

什么是正确的方法? - 有人帮帮我吗?

提前致谢。

我已经尝试过这个答案:How to change value of process.env.PORT in node.js?

但我收到此错误:(我使用的是 windows shell)

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

【问题讨论】:

标签: node.js express


【解决方案1】:

这样做 如果你想从 process.env 访问 PORT 变量,你必须使用这个命令来访问。

PORT=8081 节点服务器.js

。你使用了错误的语法

【讨论】:

    猜你喜欢
    • 2016-05-20
    • 2021-04-04
    • 1970-01-01
    • 2021-12-22
    • 2018-02-10
    • 1970-01-01
    • 1970-01-01
    • 2020-04-23
    • 1970-01-01
    相关资源
    最近更新 更多