Skip to content
Advertisement

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 Copyright (C) Microsoft Corporation. All rights reserved.

Try the new cross-platform PowerShell https://aka.ms/pscore6

PS E:Developmentcrud-node> node index.js Express server is running on port number: 8000 DB connection is successful

Advertisement

Answer

there seems to be spelling mistake in end point. The one you specified in error detail and the one defined in the code are different

Advertisement