Nodemon inspect/debug not working? - javascript

Running nodemon --inspect index.js or nodemon --debug index.js doesn't work.
Node Version : 8.9.1
Nodemon Version : 1.12.6
I have tried these with no luck :
nodemon --inspect-brk index.js
nodemon -- --inspect index.js
nodemon index.js -- --inspect index.js
nodemon index.js -- --debug index.js
nodemon -- --debug index.js
nodemon --inspect --debug index.js
nodemon --debug-brk index.js
But node --inspect index.js or node --inspect-brk index.js works. I wonder how? If any alternatives or some kinda workaround would be great too.
Please comment if you need further description.

For people coming from search engines, there could be a bug related to nodemon and ts-node.
Error: Unknown or unexpected option: --inspect
This can be a way to use inspect with nodemon:
nodemon --exec 'node --inspect=0.0.0.0:9229 --require ts-node/register src/index.ts'
For more information see here

SOLVED,
It seems like nodemon#1.12.6 was not passing in this argument. There is a newer version available 1.12.7 where everything works fine and well.
Answer source: Nodemon Issues - Github

nodemon --inspect app.js
The .js part is absolutely necessary.

FINALLY SOLVED
Just follow the below steps are you're good to go:
Make sure you have updated version of nodemon. Update is using following command: npm i nodemon#2.0.4 -g. Make sure to use -g(to give nodemon permissions to run as an administrator). If you get some warnings, try running the same with sudo command sudo npm i nodemon#2.0.4 -g
Then execute the command as: nodemon --inspect app.js
I hope it helped..!!

for anyone who is having error ARG_UNKNOWN_OPTION specially with typescript ts-nod and when using auto attach debugger in vscode
example with other arguments like dotenv
nodemon -r dotenv/config ./src/index.ts -- --inspect

As per official doc Nodemon NPM
You can also pass the inspect flag to node through the command line as you would normally:
nodemon --inspect ./server.js 80

Related

After I installed nodemon by "npm i nodemon" , when I tried to run it by "nodemon server.js" , it gives me this error. What should I do?

Screenshot form VS code terminalnodemon : The term 'nodemon' is not recognized as the name of a
cmdlet, function, script file, or operable program. Check the
spelling of the name, or if a path was included, verify that the
path is correct and try again.
I just meet that question.
First, you should make sure that you had installed nodemon in a global way (npm install -g nodemon), and make sure global package dir is in the environment variables.
Secondly, you should RESTART VScode if you are opening it now.
I spent lots of time to make sure the previous one, but it still fails, then when I restart VScode, everything is fine!
Try to install nodemon globally:
https://github.com/remy/nodemon
npm install -g nodemon
and edit Your package.json for example like that:
"scripts": {
"start": "node server",
"dev": "nodemon server"
},
then in terminal enter the command =>
npm run dev
It should works for You now ;-)
Good Luck and Best regards !
Below are some solutions
This is how you can install nodemon
npm install -g nodemon
after that you have to run this command: npm run dev
here dev is (script) server name like
{
"main": "app.js",
"scripts": {
"dev": "nodemon app.js"
},
}
after that if you are facing error like
" 'nodemon' is not recognized as an internal or external command,
operable program or batch file. "
Then after install nodemon globally write below command:
npm config get prefix
in output you will get PATH and then past this path in to the Environment Variables and it solved
Restart the terminal and run this command
nodemon run dev
I hope after that it will work properly :)
I just had to use npx instead of npm
for e.g. - npx nodemon <server.js>

NPM return “bash command not found” when I try to get a package version

I have installed the package.json that includes nodemon package (and others)
#npm list --depth 0
├─┬ nodemon#2.0.7
but the command #nodemon -v return a -bash error: "nodemon command not found”
I cant start my server.js with nodemon, the same error, but all works with #node server.js
Any idea? Thnks
With a local install
You can use npx nodemon filename.js
If you want to install it globally
With npm npm install nodemon -g or with yarn yarn global add nodemon, that way you can use nodemon directly (nodemon filename.js)

nodemon - Internal watch failed: ENOSPC: no space left on device, watch '/home/user/Documents/github/sendMail-lib/3808.txt

I am getting an error while running my server file using nodemon. When I type the command nodemon, I get the following output.
[~/D/g/sendMail-lib|3.6.5]
‹master*› »»»» nodemon 0|15:35:32
[nodemon] 1.17.5
[nodemon] to restart at any time, enter `rs`
[nodemon] watching: *.*
[nodemon] starting `node server.js`
[nodemon] Internal watch failed: ENOSPC: no space left on device, watch '/home/abdus/Documents/github/sendMail-lib/3808.txt'
[~/D/g/sendMail-lib|3.6.5]
‹master*› »»»»
Additionally, it creates almost 4000 blank text files(1.txt, 2.txt and so on).
I tried this commands but the problem still persists.
I am on Arch Linux with Node version 10.5.0, NPM version 6.1.0 and Nodemon version 1.17.5.
Just ask me if you need any more information.
I had the same problem.
Run nodemon as sudo.
$ sudo nodemon
Or
# nodemon
Most issues I run into with Arch are solved by just running as root. ;)
echo fs.inotify.max_user_watches=524288 | sudo tee -a /etc/sysctl.conf && sudo sysctl -p
Taken from here.
This is effectively a rights problem, but you don't need to use sudo, just give the user that run nodemon the rights to write to the build directory
an exemple with permissive rights (we use nodemon, so I assume we are in dev)
sudo chmod a+rwX my-application-dir
I installed nodemon locally so, I created an "npm start" script and run it as root
like so: sudo npm start
I got this error when trying to run npm start with a start script that looked like this:
"start": "nodemon server.js"
It seems that I had a global installation of nodemon, but not a local version in my project's node_modules. Once I ran npm install nodemon, it installed it locally and worked without requiring root permissions.
nodemon: v1.18.5
OS: ubuntu 18.04

bash: nodemon: command not found

I have been using nodemon for past few months now. It's just that today I got this error. I tried uninstalling nodemon and the reinstalled it. I also forced install it. Nothing worked. Whenever I run the nodemon command
bash: nodemon: command not found
pops up.
There are other answers too and I have looked them all up. They haven't worked for me.
I have faced this error once, and in my package.json, I updated the nodemon location and it worked.
Below code is in my package.json
"start" : "./node_modules/.bin/nodemon server.js"
and then after running npm start it works.
If you don't have nodemon installed globally try to do that.
I had the same issue but after installing it globally whenever I ran the command it work
sudo npm install -g nodemon
I hope this will help
This is down to your global variables.
Ensure npm is included in your PATH var and there is no conflicting npm directories
echo %PATH%
If it is, get your npm root, Ensure the npm in your global path matches the npm root
npm root -g
Navigate there and ensure the "nodemon" file is there. This is where all the npm install -g files are installed.
If not run npm i nodemon -g and confirm that it has been added to the npm root folder.
Having all of these boxes ticked will get these globals are working for you again.

Running node-inspector alongside nodemon?

I'm currently using node along with nodemon. Then I got to thinking it might be sometimes nice to use an inspector with node so have started using node-inspector
However, is it possible to run both at the same time?
Normally to run nodemon I would use:
nodemon server.js
//and similarly
node-debug server.js
I have also tried:
nodemon --debug http.js
But sadly this didn't work either.
But both together!?
If you want to run them as one command this works for me: node-inspector & nodemon --debug app.js (replacing app.js with the name of your script). If things get all mucked up you will occasionally have to kill node-inspector manually, but running the command this way gives you the option of running rs to restart nodemon manually if needed. HTH
You would start your server with nodemon --debug server.js and then you'll need to run node-inspector in a separate terminal window unless you push nodemon to the background.
For those that want an OS-independent solution and no hacks for windows, etc.
You can use npm-run-all which is a CLI tool that allows running multiple npm scripts in parallel or sequentially. So you'd set your package.json as so:
"scripts": {
"start": "npm-run-all --parallel lint start:debug start:server",
"lint": "eslint . --ext .js",
"start:debug": "node-debug server.js",
"start:server": "nodemon server.js"
}
And then from CLI, you do: npm start
Caveat: from my experience running nodemon and node-debug together leads to weird node-inspector behaviors sometimes. So i've since opted to remove nodemon from my scripts when debugging and relying on node-inspectors save-live-edit feature to change files on the fly.
I could not get nodemon to play nice with node-inspector. After one change it would restart but after that no more. Maybe it is because I am using docker containers.
The easiest way to reload the application is to let node-inspector do it (I know this is not an answer to having both run but it worked for me).
Start your application in the following way:
node-inspector --save-live-edit & \
node --debug /app/server.js
As I'm running on Linux I wrote a bash script based from rpaskett's answer so that you don't need to remember that awkward command every time.
However I noticed in a comment you're running Windows. Here are some options you have:
You could convert the bash script to Windows batch and save it as C:\Windows\System32\node-DEV.bat. I did it and it works on my Windows PC:
#echo off
echo Starting DEV environment for %1
start node-inspector
nodemon --debug %1
Then you should be able to run node-DEV server.js.
Another option; you could run something like nodedev which was written in Node.js thus platform independent, although it looks like it hasn't been updated in a while.
Or you could even run the bash script within a Cygwin environment if you had one handy.
A hacky fix for Windows users running a bash shell:
First, add node-inspector to your Path.
(You can find where npm is installing packages with npm list -g)
Then use this command in bash, or add it to your npm scripts:
START /B node-inspector && nodemon --debug server.js
START /B being the windows command to run in the background.
You must be install node-inspector and nodemon using:
npm install -g nodemon
npm install -g node-inspector
To run in Windows, make a new .bat file and add the folowing lines:
#echo off
echo Starting developer enviroment of the file %1
start nodemon --debug-brk %1
node-debug %1
And run:
node_desarrollo.bat "name of the file to run.js"
If ran with a error:
Error: listen EADDRINUSE :::5858
at Object.exports._errnoException (util.js:855:11)
at exports._exceptionWithHostPort (util.js:878:20)
at Agent.Server._listen2 (net.js:1237:14)
at listen (net.js:1273:10)
at Agent.Server.listen (net.js:1369:5)
at Object.start (_debug_agent.js:21:9)
at startup (node.js:72:9)
at node.js:980:3
Its normal because the node-inspector need to open that port to connect but because the nodemon --debug-brk %1 was opened the 5858 port its cannot open and show the EADDRINUSE :::5858 error, note that the flag --debug-brk of nodemon it's necessary to make a breakpoint on the first line. Try modifying the file.js after run the .bat and look the changes reflected on the debugger. This debugger reboots and show the changes done in the file.js. Happy coding JS!!!
{
"scripts": {
"dev": "npx nodemon --exec \"node --inspect --debug-port=0.0.0.0 src/index.js\""
}
}

Categories

Resources