DEV Community

Johnathon roy
Johnathon roy

Posted on

How to Integrate dotenv with NestJS and TypeORM

Dotenv integration with NestJS and TypeORM.

While using third party sources in application development, there must be some involvement of SSH keys or API credentials. This becomes a problem when a project is handled by a team of developers. Thus, the source code has to be pushed to git repositories periodically. Once the code is pushed to a repository, anyone can see it with the third-party keys.

A very prominent and widely used solution for this problem is using environment variables. These are the local variables containing some useful information like API keys and are made available to the application or project.

A tool known as dotenv has made it easy to create such variables and making these variables available to the application. It is an easy to use tool which can be added to your project by using any package manager.

We will use yarn as a package manager.

First, add the package using terminal.

yarn add dotenv

Since we are using NestJS which is based on typescript, so we need to add the β€œ@types” package for the same that acts as an interface between javascript and typescript package.

yarn add @types/dotenv

Since the database to be used is Postgres, so install the necessary driver for Postgres.

yarn add pg

Now install the TypeORM module to your nest project.

Dotenv integration with NestJS and TypeORM

Top comments (0)