1// .env
2your_args = your_secret
3
4// your_file.js
5
6require("dotenv").config();
7const your_args = process.env.your_args;
8// OR
9const your_args = process.env["your_args"];
10
1
2$ npm install dotenv
3
4//--------------------
5
6on file .env
7//--------------------
8DB_HOST=localhost
9DB_USER=root
10DB_PASS=s1mpl3
11DB_NAME=banco_de_dados
12DB_PORT=3306
13//--------------------
14
15import the config from .env file
16//--------------------
17
18require('dotenv').config()
19module.exports = {
20 username:process.env.DB_USER,
21 password:process.env.DB_PASS,
22 database:process.env.DB_NAME,
23 host:process.env.DB_HOST,
24 dialect:"mysql"
25}
26
1// P.S. You must install dotenv
2// npm install dotenv
3// yarn add dotenv
4// pnpm add dotenv
5
6// .env
7your_args = your_secret
8
9// your_file.js
10
11require("dotenv").config();
12const your_args = process.env.your_args;
13// OR
14const your_args = process.env["your_args"];
15
1// server.jsconsole.log(`Your port is ${process.env.PORT}`); // undefinedconst dotenv = require('dotenv');dotenv.config();console.log(`Your port is ${process.env.PORT}`); // 8626