Node JS GET API with MySQL
config.js
const mysql=require('mysql')
const con=mysql.createConnection({
host:'localhost',
user:'root',
password:'',
database:'test'
});
con.connect((err)=>{
if(err){
console.warn("error in connection");
}
})
module.exports=con;
index.js
const express=require('express');
const con=require('./config12')
const app=express();
app.get("/", (req, resp)=>{
con.query("select * from user", (err, result)=>{
if(err){
resp.send("error")
}else{
resp.send(result)
}
})
});
app.listen(5000)
Comments
Post a Comment