nestjsx / nestjs-config

Config module for nestjs using dotenv :key:
MIT License
698 stars 44 forks source link

Custom env file name #55

Closed radziszp closed 5 years ago

radziszp commented 5 years ago

Hello, as written in docs:

Note: By default the package look for a .env file in the path that you have started your server from. If you want to specify another path for your .env file, use the second parameter of ConfigModule.load().

I'd like to set different .env file for Test module. When i'm doing

ConfigModule.load(
  path.resolve(__dirname, 'config/*.{ts,js}'),
    {
      path: 'mypath/.env.test',
    }
)

I'm getting

error TS2345: Argument of type '{ path: string; }' is not assignable to parameter of type 'ConfigOptions'.

So, how should options parameter looks like?

Also is there a possibility, to extend in .env.test file values from default .env file, so wouldn't i have to duplicate code?

Thanks

bashleigh commented 5 years ago

I think I saw your question on stackoverflow ;)

That should be the correct behaviour. I'll add a test for this scenario and fix this issue.

Which version of nestjs-config are you using?

radziszp commented 5 years ago

Wasn't me, but glad i'm not the only one who couldn't fix it by himself :) I'm using v 1.2.9 Thanks! I'm looking forward for updates

bashleigh commented 5 years ago

so, update on this. There was a PR made recently where I was asked to change export ConfigOptions = {...} & EnvOptions to export interface ConfigOptions extends EnvOptions {...}. Changing it back to the latter seems to work, however I don't understand why the former doesn't work? https://github.com/nestjs-community/nestjs-config/pull/48/commits/aab42650a71d5ff9b9cb0e4b7cec57b27119f1ed#diff-11f5a2a5cc6df739d69a8a8c4f8ecffbR23

bashleigh commented 5 years ago

This should now be resolved in the next release :)

radziszp commented 5 years ago

:+1: Thanks!

Diluka commented 5 years ago

What shall I pass the path value?

// src/bootstrap.module.ts
ConfigModule.resolveSrcPath(__dirname).load('config/**/!(*.d).{ts,js}', { path: '.env.test' }),
# .env.test
DEMO=test

It doesn't load the file .env.test instead it loading .env. Seems the path options has been ignored.

bashleigh commented 5 years ago

@Diluka I think you need to add the full path. Try that and let me know how it goes. I shall have a think about whether to add a method to add the cwd path by default

Diluka commented 5 years ago

emmmm it works now. just filename. ┓( ´∀` )┏