【问题标题】:Node JS error while running { PORT=4001 npm run test} this command运行 { PORT=4001 npm run test} 这个命令时节点 JS 错误
【发布时间】:2019-07-17 18:15:10
【问题描述】:
var app= express();
const port=process.env.PORT || 4000;

app.listen(port,function(){
    console.log('Listen on port '+port);
});

当我运行这个命令时 $PORT=4001 npm run test

我看到了这个错误

PORT=4001 : The term 'PORT=4001' 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
+ PORT=4001 npm run test
+ ~~~~~~~~~
    + CategoryInfo          : ObjectNotFound: (PORT=4001:String) [], CommandNotFoundException
    + FullyQualifiedErrorId : CommandNotFoundException

【问题讨论】:

  • 我想你可能需要以export PORT=4001运行

标签: javascript node.js port


【解决方案1】:

您似乎在 PowerShell 下运行此程序,但使用的是使用 Unix/Linux shell 的某人的示例。使其成为两个命令

$Env:PORT = "4001"
npm run test

【讨论】:

    猜你喜欢
    • 2017-12-28
    • 1970-01-01
    • 2020-12-11
    • 2020-05-02
    • 2021-04-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多