javascript - 运行 { PORT=4001 npm run test} 此命令时出现节点 JS 错误
问题描述
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
解决方案
您似乎在 PowerShell 下运行它,但使用的是使用 Unix/Linux shell 的某人的示例。使其成为两个命令
$Env:PORT = "4001"
npm run test
推荐阅读
- karate - 空手道框架“no-auth”授权问题
- python - 如何从扫描的 pdf 图像中提取分块内容?
- python - Python 中烛台/OHLC 数据的模板匹配
- c# - 为什么在这种情况下会出现“类型是在未引用的程序集中定义的”?
- python - 与 cupy 的自相关
- javascript - Javascript正则表达式解析复杂的url字符串
- python - 提交时手动呈现 Django formset 重定向问题
- postgresql - Postgresql pg_profile 在创建快照时出错
- javascript - 轮播 css3 动画表现怪异
- python - 使用 TF 2.0 将 saved_model 转换为 TFLite 模型