0

I'm new to Node.js and NPM and I'm trying to spin up a local dev from a Git repository. After installing the correct versions of Node and NPM when I'm testing the server.js file but I get output that says that ENV vars are missing.

The server.js file has this snippet:

require('require-environment-variables')([
  'JWT_SECRET',
  'PROXY_URL',
]);

I have found a .travis.yml file an I have set the following:

env:
  - JWT_SECRET=xxxxx PROXY_URL=http://foo.com

However the vars are not being read because I always no matter what get a message that ENV vars are missing, this is fired by:

for (var i = 0; i < variableArray.length; i++) {
    if (!process.env[variableArray[i]]) {
        missingVariables.push(variableArray[i]);
    }
}
if (missingVariables.length) {
    console.error('Environment variables needed:', JSON.stringify(missingVariables));
    throw new Error('Environment variables missing');
}

Does my approach look correct?

Scott Weldon
  • 9,673
  • 6
  • 48
  • 67
Alan A
  • 2,557
  • 6
  • 32
  • 54
  • what is the exact content of `variableArray` – Jaromanda X Jan 19 '17 at 00:33
  • 1
    You say *"local dev"*; how are you configuring `JWT_SECRET` and `PROXY_URL` in your local environment? – cartant Jan 19 '17 at 00:45
  • Please read the description for a tag before applying it to your question. The [tag:git] tag is for questions about Git usage and workflows, not programming questions that happen to involve a Git repo. (I've [edited](//stackoverflow.com/help/editing) your question to remove it.) – Scott Weldon Jan 19 '17 at 00:50
  • 1
    The `.travis.yml` file is just for Travis CI. If you're trying to set environment variables by running the script in terminal locally, do it like this: `USER_ID=239482 USER_KEY=foobar node app.js` See [this answer](http://stackoverflow.com/a/22312793/566610) – Jared Jan 19 '17 at 00:56

0 Answers0