Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can I add a debug script to NPM?

Tags:

node.js

npm

I have edited my package.json to customize the "start" script so it adds the --debug flag to node:

  "scripts": {     "start": "node --debug server.js"   } 

Is there a way of adding new scripts for example a debug script that would do what my customized "start" is doing right now?

I'm looking to be able to execute:

npm debug 
like image 915
eliocs Avatar asked Mar 09 '12 11:03

eliocs


People also ask

Can you debug npm?

Launch via npm: Launch a Node. js program through an npm 'debug' script. If you have defined an npm debug script in your package. json, you can use it directly from your launch configuration.


2 Answers

In your package.json define the script

"scripts": {   "debug": "node --inspect server.js" } 

And then you can use npm's run-script

npm run-script debug 

or the shorter version

npm run debug 
like image 151
Dan Midwood Avatar answered Oct 04 '22 14:10

Dan Midwood


From the nodejs docs:

The legacy debugger has been deprecated as of Node 7.7.0. Please use --inspect and Inspector instead.

So starting from Node 7.7.0v use --inspect

like image 37
MatayoshiMariano Avatar answered Oct 04 '22 16:10

MatayoshiMariano