Unable to make api request to backend getting Axios network error

prathmesh
I was making one app with frontend react.js uses axios to api call and for backend i am using express and node with database mysql while making call to api url i am getting error for access denied error

    Error: ER_ACCESS_DENIED_ERROR: Access denied for user ''@'localhost' (using password: NO)

If this is not the case i will be getting axios network error

    Axios Network error

 i dont know which port to use if i use 3306 port it is already in use. Please take a look at code and suggest about optimization and a better way...


thank you....

config.js will be saving confiq for the connection db config.js

const config = {
      db: {
        host: "localhost",
        user: "new_user",
        password: "password",
        database: "db",

      },
    };

    module.exports = config;

db.js will create the connection
db.js

const mysql = require("mysql");
    const config = require("./config");

    var con = mysql.createPool(config);

    module.exports = con;

this is where the express and app server is supposed to create index.js

    const express = require("express");
    var mysql = require("mysql");
    const cors = require("cors");
    const app = express();
    app.use(express());
    app.use(cors());
    const TablesRoutes = require("./routes/TablesRoutes");
    //routes
    app.use("/", TablesRoutes);



    app.listen(8000, () => {
      console.log("Running on port :8000");
    });
api routes to call from frontend routes
    const express = require("express");
    const {
      postTableDes,
      alterTable,
      showTables,
    } = require("../Controllers/Tables");
    const tablerouter = express.Router();

    tablerouter.get("/", showTables);
    tablerouter.post("/", postTableDes);

    module.exports= tablerouter;
where showing the table act controller
    const con = require("../Config/db");
    //get tables
    const showTables = async (req, res) => {
      //try {
        var sql = `show tables`;
        const data = await con.query(sql, (err, res)=>{
          if(err){
            console.log(err);
            res.status(404).json({ error: "No show table" });
            return;
          }
          console.log(res);
          res.status(202).json(data);
        });
     module.exports = showTables;

lpizzinidev

Try to change the config.js to (the createPool call does not expect an object with db property):

const config = {
   host: "localhost",
   user: "new_user",
   password: "password",
   database: "db",
};

module.exports = config;

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

getting Network Error when calling axios get request in react js

request formData to API, gets “Network Error” in axios while uploading image

Axios: Network Error and not sending request

Post request Axios : Network error

Not able to make a GET request to the django REST API backend for the id=1 article, from axios in reactjs

Getting '400 (Bad Request)' error when making a POST request to backend API

Network error on posting a request using axios

Network Error making post request using Axios

Getting wrong error in React Axios request

In React Js Axios request getting CROS error

Axios POST/login request not working on Rails API backend

getting network error in jquery post request with json

Getting AWS API Gateway Request Id in backend api

Error in Axios API Post request in Nodejs

getting error 400 with axios post request & undefined error

axios request not going through to backend

React Native, getting network error while posting FormData with Axios

Discord bot unable to get access to the Google Sheets getting error The request is missing a valid API key

Jest returns "Network Error" when doing an authenticated request with axios

React native axios post request network error on Android physical device

Axios network error even though the post request returns 200

Network Error / 403 Forbidden on request to a service React JS axios proxy

axios showing Network request failed error in react native

unable to make api request with http ruby gem

Unable to make third-party API Request

Unable to make post request to server : 404 error

Getting error handler data from post request in AXIOS

Getting 400 error code when I run axios get request?

Getting error message when trying send request to server using axios