3

I'm deploying a node.js app on Heroku dyno and using config module that requires me to define a system variable NODE_CONFIG_DIR with the location of the config folder.

The config folder is located on my project's root.

I tried to define the system variable NODE_CONFIG_DIR using the following values, all failed:

./config
~/config
app/config
~/app/config
./app/config
$HOME/config
$HOME/app/config

I keep getting this error:

WARNING: No configurations found in configuration directory:app/config

(replace app/config with any of the values above)

I manage to set a system variable, but its value is not pointing the right place.

What is the correct way to refer to the root of my tree when using a system variable in Heroku?

David Raviv
  • 397
  • 3
  • 10
  • Assuming you can get the library to find that directory, how are you planning to populate it with configuration files? You should probably read about Heroku's [ephemeral filesystem](https://devcenter.heroku.com/articles/dynos#ephemeral-filesystem) and the way it [recommends handling configuration](https://devcenter.heroku.com/articles/config-vars). – ChrisGPT was on strike Mar 13 '19 at 15:39

3 Answers3

1

Based on documentation - if config folder is in the root of your application you should not need to specify $NODE_CONFIG_DIR env variable.


From node-config documentation:

Node-config reads configuration files in the './config' directory for the running process, typically the application root. This can be overridden by setting the $NODE_CONFIG_DIR environment variable to the directory containing your configuration files. It can also be set from node, before loading Node-config:

process.env["NODE_CONFIG_DIR"] = __dirname + "/configDir/";
const config = require("config");

$NODE_CONFIG_DIR can be a full path from your root directory, or a relative path from the process if the value begins with ./ or ../.


You could use above code to set it from your node code.

Milan
  • 1,903
  • 17
  • 16
1

You were close: /app is the correct path. You can verify it by running heroku run bash.

Stan Mazhara
  • 796
  • 4
  • 5
0

It was my bad...

Both answers are correct but didn't solve my issue.

The problem was that I used lowercase for my configuration file name while the NODE_ENV value was uppercase.

David Raviv
  • 397
  • 3
  • 10