运行{PORT = 4001 npm run test}此命令时节点JS错误

时间:2019-07-17 18:15:10

标签: javascript node.js port

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

1 个答案:

答案 0 :(得分:0)

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

$Env:PORT = "4001"
npm run test