Sometimes, we want to add environment variables with dotenv and TypeScript.
In this article, we’ll look at how to add environment variables with dotenv and TypeScript.
How to add environment variables with dotenv and TypeScript?
To add environment variables with dotenv and TypeScript, we call the dotenv.config
method.
For instance, we write
import * as dotenv from "dotenv";
dotenv.config({ path: __dirname + "/.env" });
to call dotenv.config
with an object with the path
of the environment variable file to load the key-value pairs into process.env
.
Conclusion
To add environment variables with dotenv and TypeScript, we call the dotenv.config
method.