Alex Polkhovsky
Alex Polkhovsky

Reputation: 3360

How can I set NODE_ENV variable for ironworker (iron.io) task?

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.

Upvotes: 0

Views: 137

Answers (2)

darsh
darsh

Reputation: 226

The way Iron recommends doing this is a bit annoying (http://dev.iron.io/worker/reference/configuration-variables/#config-via-file):

  1. Upload a config.json/yml file by specifying --config-file when uploading the code via the iron cli
  2. Read the path to this config file via the CONFIG_FILE environment variable inside the container
  3. Read the contents of this file, and parse them as JSON

I have another method which is easier: using arguments to npm start:

  1. In your Node code, read the environment via env = process.argv[2] || process.env.NODE_ENV
  2. Pass npm start -- <env> as the run command to the iron cli

Upvotes: 0

BrandonMoser
BrandonMoser

Reputation: 26

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.

Upvotes: 1

Related Questions