0

I have a node.js app & have some configurations based on the environment. So decided to use

https://www.npmjs.com/package/config

In accordance, I created a folder named config at the root level of the app. The folder structure looks like as below

app
  -config
   --default.json
   --local.json
   --qa.json
   --prod.json
  -src
   --routes
    ---products.ts

this is my local.json & default.json

{
 "MAX_CONNECTIONS" : 100
}

in product.ts

import { get } from 'config';
// code emitted for brievty 
const allowedConnectionsLimit = get<number>('MAX_CONNECTIONS'); //also tried with get("MAX_CONNECTIONS")

But this keeps on throwing the error

error-configuration-property-MAX_CONNECTIONS-is-not-defined

Things tried

  • uninstalled config & @types/config
  • reinstalled config & @types/config
  • moved the config folder inside src
  • rebooted the app
  • cross checked the filename & the variable name

even then this is throwing the error

Thanks!

Kgn-web
  • 7,047
  • 24
  • 95
  • 161

1 Answers1

0

You need to import config object and use config.get to read configuration value. When you use import { get } from 'config'; config library resolves incorrect this variable and therefore can't read the value.

import config from 'config';
// code emitted for brievty 
const allowedConnectionsLimit = config.get<number>('MAX_CONNECTIONS');