const { json } = require('express/lib/response');
const mysql=require ('mysql');
const express=require('express');
var app=express();
const bodyparser=require('body-parser');
app.use(bodyparser.json());
var mysqlConnection=mysql.createConnection({
host:'localhost',
user: 'root',
password:'',
database: 'employee_db'
});
mysqlConnection.connect((err)=>{
if(!err)
{
console.log("DB connection is successfull");
}
else{
console.log("DB connection failed "+JSON.stringify(err,undefined,2));
}
});
app.listen(8000,()=>console.log('Express server is running on port number: 8000'));
app.get('/employess',(res,req)=>{
mysqlConnection.query('SELECT * FROM EMPLOYEE',(err,rows,fields)=>{
if(!err)
{
console.log(rows);
}
else{
console.log(err);
}
})
});
Windows PowerShell版权所有(C)Microsoft Corporation。保留所有权利。
尝试新的跨平台PowerShell https://aka.ms/pscore6
PS E:\Development\crud-node〉node index.js Express服务器正在端口号上运行:8000 DB连接成功
1条答案
按热度按时间ql3eal8s1#
端点中似乎存在拼写错误。您在错误详细信息中指定的端点与代码中定义的端点不同