James111
James111

Reputation: 15903

Reference environment variable inside node start script

I've got a config section in my package.json which holds 2 environment variables ( port & host ). Inside my .js I'd be able to use process.env.npm_package_config_port or config_host to access the values.

Below is the config section in my node app package.json. As you can see I've added two variables into it (host and port). I'm needing to reference those values in my scripts object (Below).

"config": {
    "port":"3000",
    "host": "localhost"
  },
"scripts": {
    "start": "env NODE_ENV=DEV rnws start --hostname config.host",
    .....
}

As you can see I'm trying to refernce the config.host value inside the start script. But this doesn't work. I've also try NODE_ENV.config_host to reference the value but it doesn't work either. Any ideas?

Upvotes: 1

Views: 134

Answers (1)

zangw
zangw

Reputation: 48406

Per package.json

For Windows, please try

"start": "env NODE_ENV=DEV rnws start --hostname %npm_package_config_host%",

For Linux, please try

"start": "env NODE_ENV=DEV rnws start --hostname $npm_package_config_host",

Upvotes: 1

Related Questions