Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

291
Vistas
React: Trying to connect index.js to database but its not working

So i built a frontend where you can fill in a movie name, a review and submit it to a database. Now im trying to connect a mysql database i created to the index.js , so that it gets filled with the first entry. Im trying to accomplish it like this:

const express = require('express');
const app = express();
const mysql = require('mysql');

const db = mysql.createPool({
    host: "localhost",
    user: "root",
    password:"password",
    database:'CRUDDatabase',
});

app.get('/', (req, res) => {
    const sqlInsert = "INSERT INTO Movie_Reviews(movieName, movieReview) VALUES (1,'inception', 'good movie');" 
    db.query(sqlInsert, (err, result) =>{
        res.send("change done");
    });
})

app.listen(3001, () => {
console.log("running on port 3001")
})

But somehow the frontend gets the text ive send "Change done" but the database still doesnt show any entries. Any ideas where my mistake may be? Is it a code mistake or does it have to do with me db configuration. In mysql workbench i just created a default connection without changing anything.

EDIT: The Error seems to be the following: Error: ER_NOT_SUPPORTED_AUTH_MODE: Client does not support authentication protocol requested by server; consider upgrading MySQL client

EDIT: The following comment here solved my problem: Execute the following query in MYSQL Workbench ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'password'; Where root as your user localhost as your URL and password as your password Then run this query to refresh privileges: flush privileges; Try connecting using node after you do so. If that doesn't work, try it without @'localhost' part.

about 4 years ago · Juan Pablo Isaza
2 Respuestas
Responde la pregunta

0

I think you have an error in your code but you are not showing it as you don't test in err variable, try this code in order to show what error you are getting:

const express = require('express');
const app = express();
const mysql = require('mysql');

const db = mysql.createPool({
  host: "localhost",
  user: "root",
  password:"password",
  database:'CRUDDatabase',
});

app.get('/', (req, res) => {
  const sqlInsert = "INSERT INTO Movie_Reviews(movieName, movieReview)       VALUES (1,'inception', 'good movie');" 
  db.query(sqlInsert, (err, result) =>{
    if(err) {
       console.log(err);
       res.send(err.toString()); 
    }
    res.send("change done");
  });
})

app.listen(3001, () => {
  console.log("running on port 3001")
})
about 4 years ago · Juan Pablo Isaza Denunciar

0

So as Med Amine Bejaoui pointed out in a comment, the solution is:

Execute the following query in MYSQL Workbench ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'password'; Where root as your user localhost as your URL and password as your password Then run this query to refresh privileges: flush privileges; Try connecting using node after you do so. If that doesn't work, try it without @'localhost' part.

about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda