[英]How to set environment variables within ts file on NodeJS?
I am struggling with the following error:我正在努力解决以下错误:
error TS2591: Cannot find name 'process'. Do you need to install type definitions for node? Try `npm i --save-dev @types/node` and then add 'node' to the types field in your tsconfig.
baseUrl: process.env.TEST
// environment.prod.ts // environment.prod.ts
import 'dotenv/config';
export const environment = {
production: true,
baseUrl: process.env.TEST
};
//.env //.env
TEST=whatever
I've already installed @types/node and dotenv, the problem is the IDE on typescript files is telling me there is something wrong with TEST , what am I missing?我已经安装了@types/node 和 dotenv,问题是 typescript 文件上的 IDE 告诉我TEST有问题,我错过了什么?
Its not enough to install dotenv
package, it's types and use it right after with process.env.TEST
安装
dotenv
package 是不够的,它的类型并在process.env.TEST
之后立即使用
You also have to configure your dotenv
package in App.ts
or any root file of an application you have您还必须在
App.ts
或您拥有的应用程序的任何根文件中配置您的dotenv
package
something like this:像这样的东西:
dotenv.config({ path: __dirname + `/../.production.env}` })
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.