Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to enable debugging express.js/node.js application

I am working on express.js in window environment. I have successfully started my project with npm start. Now I need to add debug statement in package.json file to enable debugging.

Like this:

"scripts": {
  "start": "DEBUG=fibonacci:* node ./bin/www"
}

After I have edited in package.json and npm start command I am facing error:

Error: Debug is not an internal or external command

Note: I am following Node.js book and in the book it executes successfully.

like image 750
Atul Saini Avatar asked Mar 15 '26 22:03

Atul Saini


2 Answers

Setting environment variables in npm scripts is platform specific.

On Windows:

"start": "set DEBUG=fibonacci:*&& mocha --reporter spec"

On Unix / macOS:

"start": "DEBUG=fibonacci:* mocha --reporter spec"

I recommend to use cross-env (npm i -D cross-env), which deals with those differences and works on all platforms:

"start": "cross-env DEBUG=fibonacci:* mocha --reporter spec"
like image 65
jbandi Avatar answered Mar 17 '26 11:03

jbandi


i think you must set DEBUG as a environment variable

set DEBUG=you_application
like image 32
Alessio Campanelli Avatar answered Mar 17 '26 10:03

Alessio Campanelli



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!