Categories
TypeScript Answers

How to add environment variables with dotenv and TypeScript?

Spread the love

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.

By John Au-Yeung

Web developer specializing in React, Vue, and front end development.

Leave a Reply

Your email address will not be published. Required fields are marked *