0
votes

My nodejs app config = require('config') (3.0.1) returns nothing in debug. Here is the console output:

 config: 
 Config {}

NODE_ENV is only defined in development.json and loading in development has no problem.

Here is the files under ./config:

enter image description here

What could cause the config module failed to load in debug?

1
You need an index.js in the config directory. Do you want an exemple of config dir ? - Julien TASSIN
Julien TASSIN, an example would be very helpful. Thanks. - user938363
oh, sorry my bad I did not see that you used node-config, I thought you were using pure nodejs. I don't know this lib :/ - Julien TASSIN

1 Answers

1
votes

The config filenames need to be tied to the NODE_ENV or NODE_CONFIG_ENV you're setting when you run your app. (https://github.com/lorenwest/node-config/wiki/Configuration-Files#file-load-order)

You don't set NODE_ENV in the config files themselves.

So for example (assuming the command to run your app is npm start):

NODE_CONFIG_ENV=foo npm start

^ This would first load all of the config properties in default.json, then override them with any properties you set in foo.json. If you wanted to add a local.json, those properties would be a final override.

I believe it defaults to assuming your env is "development", and I'm guessing your default.json is empty.