Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

278
Views
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
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!