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.
The node-config
getmethod is designed-- and documented-- to be called as a method of aconfigobject. Try using the documented import syntax:An object method can't be expected to work the same when called as a function in JavaScript. An object method has
thisbound to the object. A function does not, unlessbind()has been explicitly called on the function to bind it to an object.