0

I am trying to integrate config package in my nx.dev typescript project. I have a config directory at root level that contains default.json

{
  "server": { "port": 3001 }
}

in my index.ts I try

import { get, util } from 'config';

console.log(util.getConfigSources());
console.log(get('server'));

and get the following:

[
  {
    name: 'path to config file.. /config/default.ts',
    original: '{\n  "server": {\n    "port": 3001\n  }\n}',
    parsed: { server: [Object] }
  }
]

Error: Configuration property "server" is not defined

And everywhere it says this is all I need to hook it up but get function throws.

Nilesh Kumar
  • 343
  • 1
  • 5
  • 18

1 Answers1

0

The node-config get method is designed-- and documented-- to be called as a method of a config object. Try using the documented import syntax:

const config = require('config');
console.log(config.get('server'));

An object method can't be expected to work the same when called as a function in JavaScript. An object method has this bound to the object. A function does not, unless bind() has been explicitly called on the function to bind it to an object.

Mark Stosberg
  • 12,961
  • 6
  • 44
  • 49