我有以下 server.js 文件,我想在通过 cmd 运行 express.js 时指定端口,例如
PORT=4000 node server.js
但是当我这样做时,我得到了错误
'PORT=4000' is not recognized as the name of a cmdlet
我也尝试过使用 SET
SET PORT=4000
但它不起作用
const express = require('express' );
const app = express();
app.use(express.static(__dirname));
const path=require('path');
var port=process.env.PORT || 53000
app.get('/',(req,res)=>{
res.sendfile(path.join(__dirname)+'/index.html');
});
app.listen(port);
不同的外壳对此有不同的语法。尝试:
视窗命令: cmd /C "set PORT=4000 && node script.js"
重击: PORT=4000 bash -c 'node script.js'
鱼: env PORT=4000 node script.js
您在 Windows 命令提示符下吗?
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句