How to add .env in your typescript projects.
nuzulfikrie

nuzulfikrie @nuzulfikrie

About: full stack developer

Location:
Kuala Lumpur
Joined:
Jun 13, 2019

How to add .env in your typescript projects.

Publish Date: Aug 12 '23
1 0

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

Comments 0 total

    Add comment