在Windows上指定PORT环境变量

问题描述 投票:0回答:1

在我的设置中,我的服务器在端口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",
}

我通常运行“纱线监视”,并且我的服务器在端口4000上运行。yarn watch2应该使其在端口5000上运行,但出现以下错误:

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

我想是因为我在Windows上工作?

我该怎么解决?

node.js windows express command-line-interface
1个回答
0
投票

npm软件包cross-env是在不同平台上设置环境变量的出色解决方案。例如,您将使用:

cross-env
© www.soinside.com 2019 - 2024. All rights reserved.