// import express js
const express = require('express')
// import a body-parser
const bodyparser = require('body-parser');
// executing the express js
const app = express();
// import mysql packages
const mysql = require('mysql');
// use bodyparser in express
app.use(bodyparser.json);
// create an connection details for mysql database
var mysqlConnection = mysql.createConnection(
{
host:'localhost',
user:'root',
password:'keerthi@abitech',
database:'employeedb'
}
)
// To connect with mysql database
mysqlConnection.connect((err)=>{
if(!err)
console.log('DB is connected')
else
console.log('DB connection is failed \n Error: ' + JSON.stringify(err, undefined, 2));
});
// establish an data fetch from database
app.get('/employees', (res, req)=>{
mysqlConnection.query('SELECT * FROM employee', (err, results)=>{
if(err) throw err;
console.log(results);
res.send("post is send")
})
});
// creating an server
app.listen(3000, ()=>console.log("server is running in port number 3000"));
这是我的密码。我无法从mysql工作台获取数据。正在加载的页面未给出任何响应。如果我通过 Postman 的链接,它显示这样无法得到任何回应
1条答案
按热度按时间emeijp431#
您当前没有将数据发送回终结点。假设您的连接成功,您应该
res.send(results)
而不是res.send("post is send")
以便将结果发送到/employees
终结点。希望这能解决你的问题。