node.js - 全局安装的node-dev导致错误 "command not found"

标签 node.js npm node-dev

这样我就不必保留 restarting node.js during development我正在尝试使用node-dev 。不幸的是,当我尝试从终端运行 node-dev 时,我收到错误:

$ node-dev server.js
-bash: node-dev: command not found

我通过 npm install node-dev -g 命令全局安装了node-dev。该命令的输出是:

npm http GET https://registry.npmjs.org/node-dev
npm http 304 https://registry.npmjs.org/node-dev
npm http GET https://registry.npmjs.org/growl
npm http 304 https://registry.npmjs.org/growl
/usr/local/share/npm/bin/node-dev -> /usr/local/share/npm/lib/node_modules/node-dev/node-dev
node-dev@0.2.9 /usr/local/share/npm/lib/node_modules/node-dev
└── growl@1.6.1

为了确保 node-dev 已全局安装,我运行了 npm ls -g ,它返回:

/usr/local/share/npm/lib
└─┬ node-dev@0.2.9
  └── growl@1.6.1

其他一些帖子表明我全局安装的 npm 模块应该位于 /usr/local/lib/node_modules 文件夹中,而不是 /usr/local/share/npm/lib/。我无法判断这是否适用于旧版本的 npm 还是真正重要的东西。

我对 Mac OS X 和 Node 开发都很陌生,所以我忽略了一些微不足道的事情并不奇怪。我没有做什么导致我在尝试使用 node-dev 时收到“命令未找到”错误?是否存在某种我忽略的 $PATH 环境问题?

需要注意的是,我没有安装 Growl,但 Node 开发文档表明它是可选的。

最佳答案

我认为这可能是你的问题,并且here's a walk-through修复它。它是专门针对 WebStorm 和 Mocha 的,但似乎可能是相关的。我认为您可能需要设置一个别名。

env: node: No such file or directory

Reason for this is that when running GUI applications under MacOSX, the environment variables are not the same as those when you run a from a terminal. In particular, node for instance is not on the path. To overcome this issue, you can either launch WebStorm from the terminal (yuck!) or solve it. Fortunately this isn’t as hard as it once was. Here’s a Tip on our forum for RubyMine but it applies to all IDE’s including WebStorm. In essence, its creating an environment.plist file inside ~/.MacOSX which contains your full path. Mine is here if you want to download it. Make sure you reboot your machine after doing this step.

Setting up an alias

Everything should be working now, but instead of having to type this in each time, lets set up an alias for it in WebStorm. Click on Preferences (CMD+, under MacOSX) and type in Command to get to the command line tools. Click on the + button to create a new entry and confirm the dialog box to create a new custom framework.

enter image description here

关于node.js - 全局安装的node-dev导致错误 "command not found",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13435188/

相关文章:

javascript - ERR_ABORTED 404(未找到)- Grunt 构建

NPM 发布注册表 - 403 Forbidden - "You don' 没有发布 "..."的权限

javascript - Node 开发不连续运行

javascript - Pusher.subscribe() 不是服务器端的函数?

node.js - 如何摆脱 : Warning: Cannot find any files matching pattern "dotenv_config_path=.env.test"

node.js - 更新后npm似乎没有更新

node.js - node-dev 未被识别为内部或外部命令

javascript - Javascript中如何处理异步?

node.js - Node.js 服务器无法在共享托管服务器上运行