node.js 如何从 WebStorm 中运行 nodemon?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/19180702/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How can I run nodemon from within WebStorm?
提问by nwinkler
I would like to use nodemonfrom within the WebStorm IDE (version 7). Nodemon watches one or more files in my source folder and restarts the node process (an Express server in this case), when one of the source files changes.
我想在 WebStorm IDE(版本 7)中使用nodemon。Nodemon 监视源文件夹中的一个或多个文件,并在其中一个源文件发生更改时重新启动节点进程(在本例中为 Express 服务器)。
How do I configure WebStorm to use nodemonin a Run Configuration, so that the node process is automatically restarted?
如何将 WebStorm 配置为在运行配置中使用nodemon,以便节点进程自动重新启动?
Without nodemon, I use the following configuration in WebStorm, but have to restart the node process whenever I change something in the source file:
如果没有nodemon,我在 WebStorm 中使用以下配置,但是每当我更改源文件中的某些内容时都必须重新启动节点进程:
- Node interpreter:
/usr/local/bin/node - Working directory:
/Users/foo/test - JavaScript file:
server.js
- 节点解释器:
/usr/local/bin/node - 工作目录:
/Users/foo/test - JavaScript 文件:
server.js
This results in a Run Configuration that runs node server.jsin the specified directory.
这将导致在node server.js指定目录中运行的运行配置。
From command line, I can use the following command to use nodemonto watch for file changes: nodemon server.jsin the project directory.
在命令行中,我可以使用以下命令使用nodemon监视文件更改:nodemon server.js在项目目录中。
How do I need to change the WebStorm configuration so that it also uses nodemon?
我需要如何更改 WebStorm 配置以使其也使用nodemon?
回答by bernhardw
It looks like the workaround with --execisn't necessary anymore, at least when using the newest version of nodemonand Webstorm 7 or 8.
看起来--exec不再需要解决方法了,至少在使用最新版本的nodemon和 Webstorm 7 或 8 时是这样。
All you have to do is specify your path to nodemonby obtaining its path with running which nodemonin your console (e.g. /usr/local/bin/nodemon) under "Node parameters":
您所要做的就是通过在“节点参数”下的控制台(例如)中运行获取其路径来指定nodemon的路径:which nodemon/usr/local/bin/nodemon


@Bela Clark, thanks for confirming.
@Bela Clark,感谢您的确认。
回答by RPDeshaies
This is the Windows solution
这是 Windows 解决方案
You can just use the nodemon.cmd instead of node directly like :
您可以直接使用 nodemon.cmd 而不是 node ,例如:
Node interpreter : C:\MyPath\To\nodemon.cmd
Node parameters : /*Empty for me*/
Node WorkingDirectoy : C:\Users\MyUserName\Desktop\DirectoryContainingMyIndex.js
JavaScriptFile : app\index.js /*or just index.js depending on your config*/
and then :
进而 :


Hope it will help you.
希望它会帮助你。
回答by Alin Ciocan
I'm on Windows and for me didn't worked with nodemon (no idea why), but someone from Jetbrains suggested to try with supervisor:
我在 Windows 上,对我来说没有与 nodemon 一起工作(不知道为什么),但是来自 Jetbrains 的人建议与主管一起尝试:
I installed supervisor:
npm install supervisor -gThen find where is
supervisorinstalled, for me was in:C:\Users\AlinC\AppData\Roaming\npm\node_modules\supervisor\lib\cli-wrapper.js –no-restart-on errorI went back to Intellij: edit configurations -> node parameters -> and added: C:\Users\AlinC\AppData\Roaming\npm\node_modules\supervisor\lib\cli-wrapper.js –no-restart-on error
我安装了主管:
npm install supervisor -g然后找到
supervisor安装的地方,对我来说是在:C:\Users\AlinC\AppData\Roaming\npm\node_modules\supervisor\lib\cli-wrapper.js –no-restart-on error我回到 Intellij:编辑配置 -> 节点参数 -> 并添加:C:\Users\AlinC\AppData\Roaming\npm\node_modules\supervisor\lib\cli-wrapper.js –no-restart-on error




回答by nwinkler
To install nodemon, use the following (if required, use sudoto run the installation with root privileges:
要安装nodemon,请使用以下命令(如果需要,请使用sudo以 root 权限运行安装:
npm install -g nodemon
This will install nodemonglobally on your machine.
这将在您的机器上全局安装nodemon。
Then, in your WebStorm Run Configuration, add the following, leaving everything else unchanged:
然后,在您的 WebStorm Run Configuration 中,添加以下内容,保持其他所有内容不变:
- Node parameters:
/usr/local/bin/nodemon --exec /usr/local/bin/node
- 节点参数:
/usr/local/bin/nodemon --exec /usr/local/bin/node
This will instruct the node interpreter to execute the nodemonscript using the following command line: node /usr/local/bin/nodemon --exec /usr/local/bin/node server.js.
这将指示节点解释执行nodemon使用下面的命令行脚本:node /usr/local/bin/nodemon --exec /usr/local/bin/node server.js。
The --execpart is important, as the execution will fail with the following error:
这--exec部分很重要,因为执行将失败并出现以下错误:
/usr/local/bin/node /usr/local/bin/nodemon server.js
4 Oct 13:56:50 - [nodemon] v0.7.10
4 Oct 13:56:50 - [nodemon] to restart at any time, enter `rs`
4 Oct 13:56:50 - [nodemon] watching: /Users/foo/test
execvp(): No such file or directory
4 Oct 13:56:50 - [nodemon] starting `node server.js`
4 Oct 13:56:50 - [nodemon] exception in nodemon killing node
Error: spawn ENOENT
at errnoException (child_process.js:980:11)
at Process.ChildProcess._handle.onexit (child_process.js:771:34)
The error seems to be caused by WebStorm not seeing the nodeexecutable on its path.
该错误似乎是由 WebStorm 未node在其路径上看到可执行文件引起的。
The fix for this is to specify the location to the nodeexecutable using the --exec /usr/local/bin/nodeparameter.
对此的修复是node使用--exec /usr/local/bin/node参数指定可执行文件的位置。
Using these settings, nodemonworks fine when run from a WebStorm Run Configuration.
使用这些设置,nodemon在从 WebStorm运行配置运行时可以正常工作。
The same trick might have to be used with some of the tools similar to nodemon, e.g. node-supervisor.
同样的技巧可能必须与一些类似于nodemon的工具一起使用,例如node-supervisor。
回答by Denko Mancheski
For those interested for the solution in Windows 10, here is my configuration. It does not show "Terminate Batch" thing and works perfectly.
对于那些对 Windows 10 中的解决方案感兴趣的人,这是我的配置。它不显示“终止批处理”的东西并且完美运行。
You press debug ONCE and than you can save change files whatever and the server will restart in debug mode. All brakepoints are working perfectly
您按下调试一次,然后您可以保存更改文件,服务器将在调试模式下重新启动。所有刹车点都运行良好
回答by user3218817
For windows users set:
对于 Windows 用户设置:
Node Interpreter: Path of the node.exe i.e. c:\program files\node\node.exe
节点解释器:node.exe 的路径,即 c:\program files\node\node.exe
Node parameter: C:\Users\YOURUSER\AppData\Roaming\npm\node_modules\nodemon\bin\nodemon.js
节点参数:C:\Users\YOURUSER\AppData\Roaming\npm\node_modules\nodemon\bin\nodemon.js
回答by Artipixel
You can also make it work with nvm and debugging still works.
您还可以使其与 nvm 一起使用,并且调试仍然有效。
Tested with Node.js 8.1.0 and Webstorm 2017.2
使用 Node.js 8.1.0 和 Webstorm 2017.2 进行测试
First make sure you are on the right version (in my case v8.1.0) and install nodemon globally -
首先确保您使用的是正确的版本(在我的情况下为 v8.1.0)并全局安装 nodemon -
nvm use v8.1.0
npm install -g nodemon
Then, open Run/Debug configurations and create a new one with the correct node interpreter.
然后,打开运行/调试配置并使用正确的节点解释器创建一个新配置。
Node parameters should be:
节点参数应该是:
MAC
苹果电脑
/Users/[YOUR_USER]/.nvm/versions/node/v8.1.0/bin/nodemon --inspect=3001
LINUX
LINUX
/usr/local/nvm/versions/node/v8.1.0/bin/nodemon --inspect=3001
Save and debug respponsibally :)
以响应方式保存和调试 :)
回答by Robert Jakubowicz
Here's the configuration that works for me on Windows 7 + WebStorm 8.0.4. If I put nodemon.cmd as the node interpreter I kept getting "Terminate batch job (Y/N)?".
这是在 Windows 7 + WebStorm 8.0.4 上适用于我的配置。如果我将 nodemon.cmd 作为节点解释器,我会不断收到“终止批处理作业(是/否)?”。


回答by peterzinho16
回答by Alexander Mills
some of these answers appear to only work for Mac. For Windows, this configuration seems to work (my user name on Windows 7 is denman).
其中一些答案似乎仅适用于 Mac。对于 Windows,此配置似乎有效(我在 Windows 7 上的用户名是 denman)。


main.js is the starting point file for my Express application.
main.js 是我的 Express 应用程序的起点文件。

