Is there a way to set/configure NODE_ENV for an ironworker task? It's not set in the process.env output. Because of that the config module loads config/development.json configuration file.
How can I set NODE_ENV variable for ironworker (iron.io) task?
141 Views Asked by Alex Polkhovsky At
2
There are 2 best solutions below
0
On
The way Iron recommends doing this is a bit annoying (http://dev.iron.io/worker/reference/configuration-variables/#config-via-file):
- Upload a config.json/yml file by specifying --config-file when uploading the code via the iron cli
- Read the path to this config file via the CONFIG_FILE environment variable inside the container
- Read the contents of this file, and parse them as JSON
I have another method which is easier: using arguments to npm start:
- In your Node code, read the environment via
env = process.argv[2] || process.env.NODE_ENV - Pass
npm start -- <env>as the run command to the iron cli
There are a couple ways to set this value. First you can send ENV params with the -e flag, as noted here https://github.com/iron-io/dockerworker/tree/master/node#2-test-locally
Iron actually recommends that you provide this information as part of the configuration and payload when creating a task.