Skip to content

Instantly share code, notes, and snippets.

@nomoney4me
Created January 24, 2019 16:23
Show Gist options
  • Save nomoney4me/21e39a4c7c1d12f6c6b0ff4ecf8783e8 to your computer and use it in GitHub Desktop.
Save nomoney4me/21e39a4c7c1d12f6c6b0ff4ecf8783e8 to your computer and use it in GitHub Desktop.
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