Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use node-inspector with `npm start` for my application?

I am using npm start to start my MEAN stack application, but I would like to use the node-inspector to debug some Mongoose. I know I can start the node inspector with node-inspector, but what can I substitute node --debug app.js with to make npm start work in my case?

This is my MEAN stack directory structure:

HTML        views/
Angular.js  public/javascript/
Express.js  routes/
Node.js     app.js
Mongoose js models/, connected in app.js
Mongo db    connected in app.js

For more information, this is my related question.

like image 585
Melissa Avatar asked Oct 12 '15 21:10

Melissa


People also ask

How do I run a node inspect?

Using the Node. To connect to it, open up Google Chrome and enter about:inspect into the URL bar and press Enter. Afterward, you will be redirected to chrome://inspect/ and be presented with a list of available devices to debug. If successful, your screen should show something similar to the image below.

Which command is used to install node inspector via npm?

Run a cmd, enter the folder and type npm install . Type npm install node-inspector again.

Does npm start use node?

If the "scripts" object does not define a "start" property, npm will run node server. js . Note that this is different from the default node behavior of running the file specified in a package's "main" attribute when evoking with node .


2 Answers

You may want to add a seperate debug script to package.json. That way you won't have to remember to revert npm start when you're finished debugging.

"scripts": {
    "start": "node ./bin/www",
    "debug": "node --debug ./bin/www"
}

Start with npm run:

$ npm run debug
like image 178
joews Avatar answered Oct 09 '22 22:10

joews


In package.json modify the start run command:

"scripts": {
    "start": "node --debug app.js"
}
like image 40
Miguel Mota Avatar answered Oct 09 '22 23:10

Miguel Mota