Tidak dapat membuat permintaan api ke belakang dengan ralat rangkaian Axios
P粉288069045
P粉288069045 2024-03-29 15:42:21
0
1
363

rreeee

config.js akan menyimpan konfigurasi penyambungan ke pangkalan data config.js

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....

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

      },
    };

    module.exports = config;

db.js will create the connection
db.js

Di sinilah pelayan ekspres dan aplikasi harus dibuat index.js

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

    var con = mysql.createPool(config);

    module.exports = con;
laluan api dipanggil dari bahagian hadapan laluan
    const express = require("express");
    var mysql = require("mysql");
    const cors = require("cors");
    const app = express();
    app.use(express());
    app.use(cors());
    const Tables路线 = require("./路线/Tables路线");
    //路线
    app.use("/", Tables路线);



    app.listen(8000, () => {
      console.log("Running on port :8000");
    });
di mana untuk menunjukkan tingkah laku jadual pengawal
    const express = require("express");
    const {
      postTableDes,
      alterTable,
      showTables,
    } = require("../控制器s/Tables");
    const tablerouter = express.Router();

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

    module.exports= tablerouter;

P粉288069045
P粉288069045

membalas semua(1)
P粉916553895

Cuba tambah atribut config.js 更改为(createPool 调用不需要具有 db pada objek):

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

module.exports = config;
Muat turun terkini
Lagi>
kesan web
Kod sumber laman web
Bahan laman web
Templat hujung hadapan
Tentang kita Penafian Sitemap
Laman web PHP Cina:Latihan PHP dalam talian kebajikan awam,Bantu pelajar PHP berkembang dengan cepat!