DEV Community

nuzulfikrie
nuzulfikrie

Posted on

How to add .env in your typescript projects.

This is a simple guide on how to use .env in a typescript project.

I am starting to learn typescript, so hopefully this will be useful to all newbie programmers using typescript out there

  1. Install dotenv library.

npm install dotenv
Enter fullscreen mode Exit fullscreen mode
  1. Include inside the file that will make use of the environment variables.
import * as dotenv from "dotenv";

dotenv.config();
Enter fullscreen mode Exit fullscreen mode
  1. Call the variables in files, like so.


export const configDev = {
  developerName: process.env.developerName,
};
Enter fullscreen mode Exit fullscreen mode

Top comments (0)