【问题标题】:Specify PORT environment variable on Windows在 Windows 上指定 PORT 环境变量
【发布时间】:2019-05-18 23:58:00
【问题描述】:

在我的设置中,我在端口 4000 上运行我的服务器。我现在想在另一个实例中在端口 5000 上运行它。我在这里读过:

https://medium.com/the-node-js-collection/making-your-node-js-work-everywhere-with-environment-variables-2da8cdf6e786

你需要做的就是:

PORT=5000 node server.js

现在,这就是我在package.json 中的内容:

"scripts": {
    "watch": "nodemon -e ts -w ./src -x npm run watch:serve",
    "watch2": "PORT=5000 yarn watch",
    "watch:serve": "ts-node --inspect src/index.ts",
}

我经常运行“yarn watch”,我的服务器在端口 4000 上运行。yarn watch2 应该让它在端口 5000 上运行,但我收到以下错误:

"'PORT' is not recognized as an internal or external command"

我认为这是因为我在 Windows 上工作?

我能做些什么来解决它?

【问题讨论】:

    标签: node.js windows express command-line-interface


    【解决方案1】:

    npm 包cross-env 是跨平台设置环境变量的绝佳解决方案。例如,您将使用:

    "scripts": {
      "watch2": "cross-env PORT=5000 yarn watch"
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2015-12-25
      • 2018-08-15
      • 1970-01-01
      • 2011-01-16
      • 2019-04-02
      • 2011-06-18
      • 2016-04-15
      相关资源
      最近更新 更多