Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why is NODE_ENV not being set by my makefile?

This is my Makefile:

start:
    make start-prod

start-dev:
    @NODE_ENV=development
    make start-bare

start-prod:
    @NODE_ENV=production
    make start-bare

start-bare:
    node src/bootstrap

test:
    @NODE_ENV=test
    mocha --ignore-leaks $(shell find ./test -name \*test.js)

.PHONY: start start-dev start-prod start-bare test

When I run make start-dev then process.env.NODE_ENV equals undefined. Why is this so?

like image 200
Tom Avatar asked Dec 28 '22 01:12

Tom


1 Answers

Inside a makefile target, each line is a separate shell instance, so setting an environment variable in one won't transfer over to the other. Instead do something like:

start-prod:
    @NODE_ENV=production \
      make start-bare

or

start-prod:
    @NODE_ENV=production make start-bare
like image 200
TooTallNate Avatar answered Jan 06 '23 15:01

TooTallNate