jwchang
jwchang

Reputation: 10864

How can I recognize NODE_ENV in Node.js?

I'm using Express for framework.

And I would like to divide my configuration to "development" and "production".

I know that I can use

app.configure('development', function() {});
app.configure('production', function() {});

But I want to know the way actually how I can know what the NODE_ENV value is.

I tried to find in global variables but I could not find.

I really need this to use other Database configuration depends on NODE_ENV

in my database config.js file.

Upvotes: 22

Views: 14770

Answers (3)

Sean McClory
Sean McClory

Reputation: 4283

Or alternatively ...

var express = require('express');
var app = express();
app.get('env');

Upvotes: 0

Dominic Barnes
Dominic Barnes

Reputation: 28429

Express also exposes this data via app.settings.env

Upvotes: 8

jwchang
jwchang

Reputation: 10864

I have found the answer

process.env.NODE_ENV

Upvotes: 49

Related Questions