0

I'm moving a node.js/express application to nest.js. The config of the app is handled with node-config (default.js and host specific js-files). I have copied the config files to the new application folder, imported the config module, and used some config.get() calls. The old application works perfect but with nest.js I get only the settings from default.js. Does anybody know why node-config is not working with nest.js?

// main.ts
import { NestFactory } from '@nestjs/core';
import { AppModule } from './app.module';
import * as config from "config";

async function bootstrap() {
    const port = Number.parseInt( config.get( "application.port" ), 10 );
    console.log( `Server listening on port: ${port}` );

    const app = await NestFactory.create( AppModule );
    await app.listen( port );
}
bootstrap();

config.get() returns always the value from default.js

Andreas N.
  • 723
  • 1
  • 7
  • 13
  • You're gonna need to show some code and what's happening. It seems like `node-config` is expecting a `conf` directory at your project root. – Jay McDoniel Mar 20 '20 at 16:22
  • Folder layout of the 2 applications is the same /src/... /config/... The nest.js application seems to find the folder because it returns the default settings from default.js in the config folder. – Andreas N. Mar 20 '20 at 16:29
  • [Is this the package you are using](https://www.npmjs.com/package/node-config)? Like I said, seeing some code and what's happening could be useful – Jay McDoniel Mar 20 '20 at 16:35
  • Its this one https://www.npmjs.com/package/config the naming is a little bit strange sometimes with/without node. – Andreas N. Mar 20 '20 at 16:41
  • I'm not sure I understand what you mean by `host specific js-files` and can't see anything immediately wrong with what you've shown. From looking at the `npm` package, it _looks_ like `config` changes what it pulls from based on `NODE_ENV` if you have things like `development.js` and `production.js`, but without seeing more, I couldn't say – Jay McDoniel Mar 20 '20 at 16:49
  • If you put files with ```.js``` in the config folder these will be used instead of the ```default.js```. – Andreas N. Mar 21 '20 at 07:12

1 Answers1

0

Found the problem, there must be some changes between versions 2 and 3 of the config module that made the filename loading algorithm case sensitive. Going back to v2 solved the problem. :-)

Andreas N.
  • 723
  • 1
  • 7
  • 13