0

what is the problem here? here is the code i am stuck past 2 days i read almost all the articles and could not find the solution.

    const express = require("express");
    const bodyParser = require("body-parser");
    const passport = require("passport");
    const mysql = require("mysql");
    //const users = require("./routes/user");

    const app = express();
    //app.use(passport.initialize());
    //require("./passport")(passport);

    const db = mysql.createConnection({
    host: "localhost",
    user: "root",
    password: "",
    database: "users"
    });

db.connect(function(err) {
  if (err) {
    enter code herereturn console.error("error: " + err.message);
  }

  console.log("Connected to the MySQL server.");
});
global.db = db;

app.use(bodyParser.urlencoded({ extended: false }));
app.use(bodyParser.json());

//app.use("/api/users", users);

app.get("/", function(req, res) {
  res.send("hello");
});

const PORT = process.env.PORT || 5000;

app.listen(PORT, () => {
  console.log(`Server is running on PORT ${PORT}`);
});
user207421
  • 305,947
  • 44
  • 307
  • 483

1 Answers1

0

You need to run this in a sql console:

ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY ''

Or this if you have a password:

ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'your_password'

Check this link for more info about it.