CaptnHirni
CaptnHirni

Reputation: 157

process.env.NODE_ENV is set but still undefined

I need to pass a variable when calling gulp, so I one can manage different builds. I am on Win7 and tried to set NODE_ENV like set NODE_ENV=prod .. then I start gulp

..in the gulpfile there is only a output

var gulp = require('gulp');

gulp.task('default', function() {
    console.log(process.env.NODE_ENV);
});

but process.env.NODE_ENV is always undefined(?)

[23:53:55] Using gulpfile F:\DevOps\gulpEnvTest\gulpfile.js
[23:53:55] Starting 'default'...
undefined
[23:53:55] The following tasks did not complete: default
[23:53:55] Did you forget to signal async completion?

Why is that? .. I also tried other things like cross-env, but this also does not work.

Upvotes: 0

Views: 894

Answers (1)

Sergey Mell
Sergey Mell

Reputation: 8040

According to this answer when using set NODE_ENV=prod you are just setting it in the current process space.

You should use setx NODE_ENV prod to set the var to system environment variable level.

Upvotes: 1

Related Questions