Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I set NODE_ENV and DEBUG?

Tags:

node.js

NODE_ENV=dev node server.js

That is the start script in my package.json file. So, I start the app with npm start

I want to use the debug module, but I am unsure how to set multiple environment variables when starting the app as I am above.

How would I add DEBUG=* to the start script above?

like image 666
Coder1 Avatar asked Jan 03 '15 04:01

Coder1


2 Answers

You can simply use:

NODE_ENV=dev DEBUG=* node server.js

and in your package.json file:

{
  "name": "yourApp",
  "version": "0.0.0",
  "description": "",
  "main": "index.js",
  "scripts": {
    "start": "NODE_ENV=dev DEBUG=* node index.js"
  },
  "author": "",
  "license": "ISC",
  "dependencies": {

    ...

  }
}
like image 126
agconti Avatar answered Nov 15 '22 08:11

agconti


The answer is already given but I will add some more detail as I was looking for debugging only request.

To work with express

NODE_ENV=dev DEBUG=express:* node server.js 

or

NODE_ENV=dev DEBUG=myapp node server.js

and as mention by @agconti

NODE_ENV=dev DEBUG=* node server.js

To debug particular namespace

NODE_ENV=dev DEBUG=request:* node server.js

You can also exclude particular namespace

By prefixing them with a "-" character. For example, DEBUG=*,-request:* would include all debuggers except those starting with "request:".

like image 41
Adiii Avatar answered Nov 15 '22 08:11

Adiii