NodeJS environment variables in Grunt

use the grunt-env plugin: https://npmjs.org/package/grunt-env

and set your config:

grunt.initConfig({
  env : {
    options : {
      //Shared Options Hash
    },
    dev : {
      NODE_ENV : 'development',
      DEST     : 'temp'
    }
  },
  'another-task': {}
});

in your gruntfile you will probably define some default-task:

grunt.registerTask('default', ['env', 'another-task']);

so if you run ‘grunt default’ at first your env-vars are set, and then ‘another-task’ is run

if you want to specify the current environment via command-line option you could use grunt.option:

grunt.initConfig({
  env : {
    options : {
      //Shared Options Hash
    },
    dev : {
      NODE_ENV : grunt.option('environment') || 'development',
      DEST     : 'temp'
    }
  },

in this example if you call your grunt task with --environment=production production will be set, otherwise development will be set

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)