Last active
August 9, 2021 10:14
-
-
Save Adurtxi/863ad3db34f712b3e65a8d1a64a6cbfb to your computer and use it in GitHub Desktop.
Database Config of NodeJS Backend wih Express and MySQL using DotEnv
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 'use strict'; | |
| const mysql = require('mysql'); | |
| //- NEW | |
| require('dotenv').config(); | |
| const { DB_HOST, DB_USER, DB_PASS, DB_DATABASE } = process.env; | |
| //- | |
| //- UPDATED | |
| const dbConnection = mysql.createConnection({ | |
| host : DB_HOST, | |
| user : DB_USER, | |
| password : DB_PASSWORD, | |
| database : DB_DATABASE | |
| }); | |
| //- | |
| dbConnection.connect((err) => { | |
| if (err) throw err; | |
| console.log('Database Connected!'); | |
| }); | |
| module.exports = dbConnection; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment