javascript - why can't I access value NODE_ENV in my server.js file when I have set it gruntfile.js with grunt-env -
i trying set options using env in gruntfile.js can use node_env based if statements in server.js file.
i have installed grunt-env using "npm grunt-env --save-dev" , included , env section in gruntfile.js:
grunt.initconfig({ pkg: grunt.file.readjson('package.json'), env: { dev: { node_env : 'development' }, prod: { node_env : 'production' } }, ....
i registered tasks dev , production @ end of file
grunt.registertask('dev', ['csslint', 'jshint', 'nodeunit', 'sass', 'concurrent', 'nodemon']); grunt.registertask('prod', ['cssmin', 'uglify', 'nodemon']);
when run "grunt dev" or "grunt prod" server starts without error , starts correct tasks, still not able access node_env form inside server.js file. tried adding following:
console.log(process.env.node_env);
this returns "undefined" no matter if use "grunt dev" or "grunt prod"
where going wrong?
add grunt-env task before order tasks;
grunt.registertask('dev', ['env:dev', 'csslint', 'jshint', 'nodeunit', 'sass', 'concurrent', 'nodemon']); grunt.registertask('prod', ['env:prod', 'cssmin', 'uglify', 'nodemon']);
Comments
Post a Comment