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

Jamie Hutber
  • 26,790
  • 46
  • 179
  • 291

8 Answers8

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

rpaskett
  • 456
  • 1
  • 3
  • 13
  • 1
    This should be marked as the right answer actually. Because this just work!!! No need for two windows – Moataz Elmasry May 24 '15 at 11:41
  • 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? – Jörn Berkefeld Jun 26 '15 at 08:17
  • 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. – grant Oct 30 '15 at 15:22
  • 4
    @JörnBerkefeld The & means "run in background" in Unix only. Windows has different commands. See this: http://superuser.com/a/591084/69693 – Alex Nov 07 '15 at 11:33
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.

Paul
  • 35,689
  • 11
  • 93
  • 122
  • 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 :) – Jamie Hutber Sep 14 '14 at 00:00
  • Where do you run node-inspector? – Paul Sep 15 '14 at 16:35
  • 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? – Jamie Hutber Jan 28 '15 at 00:10
  • 1
    For those that want a more reliable solution and one that works without windows hacks- see my answer below. – olive_tree Oct 14 '16 at 22:05
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.

olive_tree
  • 1,417
  • 16
  • 23
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
HMR
  • 37,593
  • 24
  • 91
  • 160
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.

Community
  • 1
  • 1
mattbell87
  • 565
  • 6
  • 9
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.

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

LordZero
  • 11
  • 1
0
{
    "scripts": {
        "dev": "npx nodemon --exec \"node  --inspect --debug-port=0.0.0.0  src/index.js\""
    }
}
Erick Wendel
  • 402
  • 6
  • 14