I have installed nodemon
as a global package in my system. It works when I executed nodemon
in cmd.
But when I am using vscode with this launch.json
file, vscode throws this exception:
request launch: runtime executable XXX\XXX\XXX\XXX\nodemon does not exists
the launch.json is:
{ "version": "0.2.0", "configurations": [ { "name": "Launch", "type": "node", "request": "launch", "program": "app.js", "stopOnEntry": false, "args": [], "cwd": ".", "runtimeExecutable": nodemon, "runtimeArgs": [ "--nolazy" ], "env": { "NODE_ENV": "development" }, "externalConsole": false, "preLaunchTask": "", "sourceMaps": false, "outDir": null }, { "name": "Attach", "type": "node", "request": "attach", "port": 5858 } ] }
when I erase the nodemin in runtimeExecutable
it runs perfectly with node
If you get this error: nodemon: command not found , it means nodemon was not installed properly. Try using this: sudo npm install -g --force nodemon , which worked in my case. If you are using Windows, npm i -g nodemon should work. Edit and save your app to see nodemon in action.
First, install nodemon as a dev dependency:
npm install --save-dev nodemon
For newer versions of VS Code set up your .vscode/launch.json
file like this:
{ "version": "0.2.0", "configurations": [ { "type": "node", "request": "launch", "name": "nodemon", "runtimeExecutable": "${workspaceFolder}/node_modules/nodemon/bin/nodemon.js", "program": "${workspaceFolder}/app.js", "restart": true, "console": "integratedTerminal", "internalConsoleOptions": "neverOpen" }] }
The most important pieces are the runtimeExecutable
property that points to the nodemon script and the program
property that points to your entry point script.
If you use an older VS Code (which you shouldn't), try this launch configuration:
{ "version": "0.2.0", "configurations": [ { "name": "Launch with nodemon", "type": "node", "request": "launch", "program": "${workspaceRoot}/node_modules/nodemon/bin/nodemon.js", "args": ["${workspaceRoot}/app.js"], "runtimeArgs": ["--nolazy"] } ] }
The most important pieces are the program
property that points to the nodemon script and the args
property that points to your normal entry point script.
I couldn't get @AdrianT's answer working with the debugger attached. It seems like there's a newer built-in supported way to do this:
It will add something like this to your launch.json:
{ "type": "node", "request": "launch", "name": "nodemon", "runtimeExecutable": "nodemon", "program": "${workspaceRoot}/app.js", "restart": true, "console": "integratedTerminal", "internalConsoleOptions": "neverOpen" }
Make sure your "program" setting is your correct entry point script.
You need to install nodemon globally to get this to work (npm install -g nodemon) (as per the documentation)
Your app now runs and you can set breakpoints which will be hit and the console logs to the integrated terminal window.
Note that terminating the debug session only terminates the program to debug, not nodemon itself. To terminate nodemon, press Control-C in the integrated terminal.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With