我正在尝试从 phpmyadmin 数据库中获取信息,但在浏览器中它显示不能 get/employee 并且在命令提示符中没有错误
I am trying to fetch information from phpmyadmin database, but in browser it's showing cannot get/employee and in command prompt there is no error
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>节点index.js
Express 服务器是 运行,端口号为:8000
数据库连接成功
终点好像有拼写错误。您在错误详细信息中指定的和代码中定义的不同
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>节点index.js Express 服务器是 运行,端口号为:8000 数据库连接成功
终点好像有拼写错误。您在错误详细信息中指定的和代码中定义的不同