I want to add my database environment variables to a .env file and use that file in my Javascript program in order to create a connection to my database using Node.js.
So here is my database info which I use to create connection with:
var con = mysql.createConnection({
host: "localhost",
user: "root",
password: "my password",
database: "mydatabase"
});
Then I try to check if I am connected to my database using these lines:
(It should print "Connected!").
con.connect(function(err) {
if (err) throw err;
console.log("Connected!");
});
I want to put the first block of code in another file and require that file in my Node.js program.
How should I do this? How should I require the file? Thank you in advance :)
