Dotenv Example
January 22, 2020
Install dotenv
$ npm install dotenv
Create .env
file
- note Make sure to create it in the root of your project
.env
DB_PASSWORD=password
Add .env
to your .gitignore
file
node_modules
.env
sample.js
var mysql = require("mysql");
require("dotenv").config();
var connection = mysql.createConnection({
host: "localhost",
// Your port; if not 3306
port: 3306,
// Your username
user: "root",
// Your password
password: process.env.DB_PASSWORD,
database: "ice_creamDB"
});
connection.connect(function(err) {
if (err) throw err;
console.log("connected as id " + connection.threadId + "\n");
createProduct();
});