3

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.

5 Answers 5

5

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"
Sign up to request clarification or add additional context in comments.

Comments

2

i think you must set DEBUG as a environment variable

set DEBUG=you_application

6 Comments

that way it works...but it temporarily ,i mean closing and starting the command prompt i need to set it again.Is there any way it can work by editing the package.json???
if you try from console: 1. cd in your app 2. npm install 3. set DEBUG=app 4. npm start It should not be temporary...
But, he will have to repeat these steps, everytime when he opens up a new CMD window right?
with WebStorm, i set this variable from Edit Configurations... in windows i think it's possible in this way: - Use the global Search Charm to search "Environment Variables" - Click "Edit system environment variables" - Click "Environment Variables" in the dialog. - In the "System Variables" box, search for Path and edit it to include C:\Program Files\nodejs .
iam not sure how it will help after adding path C:\Program Files\nodejs,but i tried and it not works
|
2

Answers above are correct but they are just cmd session based ,if we close cmd then we need to set the debug variable again. after some debugging i found the correct way

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

we just need to put the set command in the package.json file itself,In that way you can store as many as variable you want like port also.

Comments

1

The way I do it:

set DEBUG=your_project:* & npm start

Comments

0

With nodemon, on windows:

"scripts": {
  "start": "SET \"DEBUG=express:*\"&& nodemon ./bin/www"
},

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.