0

I want environmental exclusive configs. I see process.env is referred to often, but I have not seen it documented anywhere where these values should be but.

I saw a .env file in my project folder and I tried putting a value there

foo=bar

right under

cloudinary_url=...

However upon calling process.env.foo in code, I don't get anything.

How should this be done?

Glstunna
  • 1,993
  • 3
  • 18
  • 27

1 Answers1

0

You are correct. The .env file is in your project folder. Did you require it in your keystone.js file?

At the top of your keystone.js file should be:

require('dotenv').load();

Also, be sure your starting directory is the same where the keystone.js file is. If you are starting KeystoneJS like this:

node ./your-project/keystone.js

You should take care about NodeJS directory change. Try to put this at the top of your keystone.js file:

console.log('Starting environment: ' + process.env.NODE_ENV);

if (process.env.HOME && process.env.NODE_ENV == 'production') {
    console.log('Starting directory: ' + process.cwd());
    try {
      process.chdir(process.env.HOME);
      console.log('New directory: ' + process.cwd());
    }
    catch (err) {
      console.log('chdir: ' + err);
    }
}

require('dotenv').load();
jackoob
  • 86
  • 7