Running node-inspector alongside nodemon?
Asked Answered
H

8

29

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!?

Haematothermal answered 11/9, 2014 at 22:36 Comment(1)
"node-inspector & nodemon --debug filename.js" should work just great. Just one command -line requiredFroward
P
17

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.

Penumbra answered 11/9, 2014 at 23:6 Comment(4)
Umm nice idea, I just can't get it to work. Maybe I am expecting more from the inspector? However I do the following nodemon --debug src/index.js I then open another cmd and do node-debug index.js I'm on windows btw :)Haematothermal
Where do you run node-inspector?Penumbra
Took me time to get back to here :) But I had to start another project and then moved house. But I'm back baby! One thing though @paul. I may have mis understood what the node-inspector is actually for. I was hoping that if I console.log something in my node files they would output in NI. I guess this isn't the case?Haematothermal
For those that want a more reliable solution and one that works without windows hacks- see my answer below.Scrotum
R
28

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

Reentry answered 29/9, 2014 at 3:27 Comment(4)
This should be marked as the right answer actually. Because this just work!!! No need for two windowsFries
not working for me with node-inspector v0.10.2 and nodemon v1.3.7 in Win7. it will just load node-inspector - any ideas?Decadence
This is the best way to do it an ensures that node-inspector gets code updates when nodemon updates itself. Other methods "work" but aren't as efficient. Would hope this gets marked as the accepted answer.Magree
@JörnBerkefeld The & means "run in background" in Unix only. Windows has different commands. See this: superuser.com/a/591084/69693Tello
P
17

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.

Penumbra answered 11/9, 2014 at 23:6 Comment(4)
Umm nice idea, I just can't get it to work. Maybe I am expecting more from the inspector? However I do the following nodemon --debug src/index.js I then open another cmd and do node-debug index.js I'm on windows btw :)Haematothermal
Where do you run node-inspector?Penumbra
Took me time to get back to here :) But I had to start another project and then moved house. But I'm back baby! One thing though @paul. I may have mis understood what the node-inspector is actually for. I was hoping that if I console.log something in my node files they would output in NI. I guess this isn't the case?Haematothermal
For those that want a more reliable solution and one that works without windows hacks- see my answer below.Scrotum
S
1

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.

Scrotum answered 14/10, 2016 at 22:3 Comment(0)
J
0

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
Janniejanos answered 1/6, 2015 at 3:3 Comment(0)
T
0

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.

Trisect answered 31/12, 2015 at 4:5 Comment(0)
S
0

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.

Symbolize answered 18/1, 2016 at 7:30 Comment(0)
E
0

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!!!

Elwina answered 21/3, 2016 at 4:5 Comment(0)
C
0
{
    "scripts": {
        "dev": "npx nodemon --exec \"node  --inspect --debug-port=0.0.0.0  src/index.js\""
    }
}
Cyclonite answered 27/12, 2019 at 17:8 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.