Dotenv Tool


Dotenv

Intro

dotenv is a tool helps us to access variables in .env file in anywhere under the project.

In nodejs

installation

npm install dotenv --save

import and use it under app.js

require('dotenv').config()
console.log(process.env)

once the dotenv is imported under the most top file (app.js), no need to require it in other files. Directly use the syntax:

process.env.[variable.name]

to access the variable

in react

installatation

npm install react-dotenv

import and use

import React from "react";
import env from "react-dotenv";

export function MyComponent() {
  return <div>{env.API_URL}</div>;
}

A u t h o r: Joe
P o l i c y: All articles in this blog are used except for special statements CC BY 4.0 reprint policy. If reproduced, please indicate source Joe !
Leave Your Comment Here
  TOC