我正在开发node.js,并希望兼顾生产和开发环境.我发现在运行node.js服务器时设置NODE_ENV可以完成这项工作.但是,当我尝试在package.json脚本中设置它时,它给了我错误:
NODE_ENV is not recognised as an internal or external command
下面是我的package.json
{ "name": "NODEAPT","version": "0.0.0","private": true,"scripts": { "start": "NODE_ENV=development node ./bin/server","qa2": "NODE_ENV=qa2 node ./bin/server","prod": "NODE_ENV=production node ./bin/server" },"dependencies": { "body-parser": "~1.15.1","cookie-parser": "~1.4.3","debug": "~2.2.0","express": "~4.13.4","fs": "0.0.1-security","jade": "~1.11.0","morgan": "~1.7.0","oracledb": "^1.11.0","path": "^0.12.7","serve-favicon": "~2.3.0" } }
我运行我的节点服务器为:npm run qa2例如.
我不知道我做错了什么.任何帮助表示赞赏
解决方法
由于您使用的是Windows操作系统,因此该命令与您使用的unix系统命令不同.
在Windows中,您必须将脚本修改为.
"scripts": { "start": " SET NODE_ENV=development & node ./bin/server","qa2": "SET NODE_ENV=qa2 & node ./bin/server","prod": "SET NODE_ENV=production & node ./bin/server" },
使用SET,然后使用&之后.
但是,建议使用cross-env npm软件包来实现跨平台稳定性.
像npm install -S cross-env一样安装它
"scripts": { "start": " cross-env NODE_ENV=development & node ./bin/server","qa2": "cross-env NODE_ENV=qa2 & node ./bin/server","prod": "cross-env NODE_ENV=production & node ./bin/server" },