0

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?

user938363
  • 9,990
  • 38
  • 137
  • 303

1 Answers1

1

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.

Ben Chamberlin
  • 671
  • 4
  • 18
  • All setting goes to the default.json as well. The issue is the the config is loaded successfully in normal development (for ex, when node index.js) but not in debug with VS code. I posted on VS code to find out if this is something related to the IDE. – user938363 Mar 23 '19 at 18:16