shiva
shiva

Reputation: 5489

Running gulp and set environment in Windows

I am using Windows 10 Pro. Recently I changed from Ubuntu to Windows 64-bit. In Ubuntu I ran node.js applications by setting the environment variable and using node.js package gulp. Now I don't know how to run both commands at a time in Command Prompt or Windows PowerShell. I installed git-bash and Cygwin too.

Below I'm providing the command which I used in Ubuntu. I searched Google and Github. Nothing helped me. I installed gulp globally.

Command is env ENV=development gulp in Ubuntu.

Upvotes: 1

Views: 2859

Answers (2)

Ashok JayaPrakash
Ashok JayaPrakash

Reputation: 2293

Approach I

Create a batch file and set all the required environment values & execute your command

build.bat:

set ENV=development
start cmd /k "cd <app-directory> & call gulp"

Approach II

Setting environment value in package.json

{
  "name": "myapp",
  "scripts": {
    "gulp": "ENV='development' gulp"
  },
  ...
}
npm run gulp // Command to run the gulp task

Approach III

Setting environment value in gulpfile.js gulp-env module

// gulpfile.js
var gulp = require('gulp');
var nodemon = require('nodemon');
var env = require('gulp-env');

gulp.task('nodemon', function() {
    // nodemon server (just an example task)
});

gulp.task('set-env', function () {
  env({
    vars: {
        ENV: "development"
    }
  })
});

gulp.task('default', ['set-env', 'nodemon'])

Upvotes: 0

Ansgar Wiechers
Ansgar Wiechers

Reputation: 200373

Defining a (volatile) environment variable and executing a command in CMD:

set "ENV=development"
gulp

In one line:

set "ENV=development" & gulp

Defining a (volatile) environment variable and executing a command in PowerShell:

$env:ENV = 'development'
& gulp

In one line:

$env:ENV = 'development'; & gulp

Upvotes: 2

Related Questions