Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

279
Visualizações
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 à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda