Created
January 24, 2019 16:23
-
-
Save nomoney4me/21e39a4c7c1d12f6c6b0ff4ecf8783e8 to your computer and use it in GitHub Desktop.
This file contains 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
const express = require('express') | |
const app = express(); | |
// dependencies | |
var mysql = require("mysql"); | |
// db connection settings | |
var con = mysql.createConnection({ | |
host:"localhost", | |
user:"root", | |
password:"xxx", | |
database:"xxxx" | |
}); | |
app.get('/', (req,res) => { | |
// connect to the database | |
con.connect(function(err){ | |
if(err) | |
console.log(err) | |
else | |
var sql = "SELECT * FROM employee"; | |
con.query(sql, function(err, data){ | |
if(err){ | |
console.log(err) | |
} | |
else{ | |
data.forEach(function(record){ | |
//console.log(record.emp_id, record.sex); | |
res.send(JSON.stringify(record)) | |
}); | |
} | |
}); | |
}); | |
}) | |
app.listen(3000) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment