[英]How to set up environment variables for node.js in NPM task
I have npm
task that loads concurrently, node-inspector, and node-supervisor. 我有同时加载的
npm
任务,节点检查器和节点管理器。
{
"start": "concurrently --kill-others \"node-inspector\" \"set NODE_PATH=.&&supervisor -n error -- ./bin/www --debug\"",
"prestart": "start chrome http://localhost:3000 http://localhost:8080/debug?port=5858"
}
Result: 结果:
[1] set NODE_PATH=.&&supervisor -n error -- ./bin/www --debug exited with code 0
--> Sending SIGTERM to other processes..
[0] Node Inspector v0.12.7
[0] Visit http://127.0.0.1:8080/?port=5858 to start debugging.
But when I'm trying localhost:3000
I get ERR_CONNECTION_REFUSED
. 但是当我尝试
localhost:3000
我得到了ERR_CONNECTION_REFUSED
。
QUESTION 1: How I can pass NODE_PATH=.
问题1:我如何通过
NODE_PATH=.
(or any other ENV variable) to supervisor - so my node runs correctly? (或任何其他ENV变量)传递给主管-那么我的节点是否正常运行?
QUESTION 2: Or maybe you know, how to organize two watch tasks within npm
scripts? 问题2:或者也许您知道,如何在
npm
脚本中组织两个监视任务? for example: node-supervisor
and node-inspector
例如:
node-supervisor
和node-inspector
Note1: If I run set NODE_PATH=.&&supervisor -n error -- ./bin/www --debug
directly from command line - works well. 注1:如果我直接从命令行运行
set NODE_PATH=.&&supervisor -n error -- ./bin/www --debug
- 效果很好。
Note2: If I run npm start
without NODE_PATH=.&&
it works well but node error - cause it can't find modules for example require('helpers/log')
or require('models/user')
cause i don't want to place everything in node_modules
. 注意2:如果我运行
npm start
而没有NODE_PATH=.&&
它运行良好但是节点错误 - 导致它无法找到模块,例如require('helpers/log')
或者require('models/user')
因为我没有想要将所有内容放置在node_modules
。
Stats: 统计:
For your first question, check out the handy helper module cross-env
对于第一个问题,请查看方便的辅助模块
cross-env
It's designed for exactly this purpose, and is easy to use. 它专为此目的而设计,易于使用。 Just use
cross-env
where you'd typically use UNIX-style env, and away you go. 只需使用
cross-env
,你通常使用UNIX风格的环境,然后离开。 Mine, for example, looks like: 例如,我的看起来像:
"scripts": {
"start": "cross-env DEBUG=express:router webpack-dev-server ...."
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.