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

284
Vistas
MySql and node.js error when trying to establish connection in my react app

For my react app I have a sign in component that we want to call a signup function that is held in a separate dbUtils file, the functions work when the file is run by itself but when it is called in the react component I am getting the error message.

TypeError: Net.createConnection is not a function

  71 | this._connectCalled = true;
  72 | 
  73 | // Connect either via a UNIX domain socket or a TCP socket.
> 74 | this._socket = (this.config.socketPath)
     | ^  75 |   ? Net.createConnection(this.config.socketPath)
  76 |   : Net.createConnection(this.config.port, this.config.host);
  77 | 

This is the SignIn.js component in our react app


import * as db from '../utils/dbUtils.js';

const SignInModal = ({ showSignIn, setShowSignIn }) => {

    // ---- ERROR FURTHER BELOW ----

    const modalRef = useRef();

    const [showSignUp, setShowSignUp] = useState(false);

    function submitForm() {

        if (showSignUp) {
            db.signUp(); 
        }

        setShowSignIn(false);
        values.email = '';
        values.username = '';
        values.password = '';
        values.password2 = '';
    }

    useEffect(
        () => {
            document.addEventListener('keydown', keyPress);
            db.initCon(); //<----------------------- ERROR OCCURS HERE -------------

            return () => document.removeEventListener('keydown', keyPress);
        },
        [keyPress]
    );
    return (
        <>
           <div>lots of html</div>
        </>
    );
}

export default SignInModal


this is the javascript file containing our sql injection logic dbUtils.js

var mysql = require('mysql');
var connection;
var loggedIn = false;
var currAccId;

export function initCon(){
  connection = mysql.createConnection({
    host     : '---', // <-- taken out for this post
    user     : '---',
    password : '---' 
  });
  connection.connect();
}

export function endConn(){
  connection.end();
}

export function signUp(dispName, email, pw){
  connection.query("INSERT INTO typeTestdb.user_table (display_name,user_email,password) VALUES (?,?,?);",[dispName, email, pw], function (error, results) {
    if (error) {
      console.log("Email already registered! Try logging in!");
    } else {
      console.log('Account Created');
    }
  });
}


about 4 years ago · Juan Pablo Isaza
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