admin管理员组文章数量:1318564
I'm trying to set configuration variables on my project using the official documentation.
I added the following line to my app.module.ts imports:
ConfigModule.forRoot({
isGlobal: true
}),
I created a .env file at the root of my project with the following content:
MY_VARIABLE=myself
And I use dependecy injection to get access to the configuration service:
constructor(private configService: ConfigService) {}
However the following line logs 'Env variable: undefined'
console.log('Env variable: ', this.configService.get<any>('MY_VARIABLE'));
I'm trying to set configuration variables on my project using the official documentation.
I added the following line to my app.module.ts imports:
ConfigModule.forRoot({
isGlobal: true
}),
I created a .env file at the root of my project with the following content:
MY_VARIABLE=myself
And I use dependecy injection to get access to the configuration service:
constructor(private configService: ConfigService) {}
However the following line logs 'Env variable: undefined'
console.log('Env variable: ', this.configService.get<any>('MY_VARIABLE'));
Share
Improve this question
asked Apr 26, 2020 at 9:45
PlatusPlatus
1,5079 gold badges29 silver badges59 bronze badges
1
- Sounds like you've got it set up properly. Can you share a reproduction? In the snippets you've provided I can't see a problem. – Jay McDoniel Commented Apr 26, 2020 at 16:08
2 Answers
Reset to default 5Several scenarios:
- You don't have
.env
file .env
is incorrectly defined- You're trying to access environmental variables from
.env
located outside the server's root path - You need to install
dotenv
package - Deploying to Serverless and in the
functions
(or other deployable folder) the.env
is missing (even though it's in the root location it has to be there too)
I have the same problem. Then I figure out that I have imported process from import process from 'node:process';
this is not needed. After removing this its working fine.
本文标签: javascriptNestJS env variable undefinedStack Overflow
版权声明:本文标题:javascript - NestJS env variable undefined - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742049439a2417985.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论