0

I've searched all over and cannot find a resolution. Here is my code:

 var express    = require("express");
 var mysql      = require('mysql');
 var connection = mysql.createConnection({
   host     : 'localhost',
   user     : 'root',
   password : 'pass',
   database : 'mysql_db',
   port: 3306
 });
 var app = express();

 connection.connect(function(err){
 if(!err) {
     console.log("Database is connected ... \n\n");
 } else {
     console.log("Error connecting database ... \n\n");
 }
 });

 app.listen(3306, 'localhost');

I'm running it using the command "nodemon server.jsx" and I get the error:

Error: listen EACCES 127.0.0.1:3306
    at Object._errnoException (util.js:992:11)
    at _exceptionWithHostPort (util.js:1014:20)
    at Server.setupListenHandle [as _listen2] (net.js:1338:19)
    at listenInCluster (net.js:1396:12)
    at GetAddrInfoReqWrap.doListen [as callback] (net.js:1505:7)
    at GetAddrInfoReqWrap.onlookup [as oncomplete] (dns.js:97:10)

Can anyone please help me?

Neil Lunn
  • 148,042
  • 36
  • 346
  • 317
  • Why is your file `.jsx`? – Maximilian Burszley Jun 01 '18 at 01:19
  • I'm working on a react app to use with this database and read that js and jsx were interchangeable. I just got so used to naming the files jsx and didn't think it really mattered. – Gabriel Garcia Jun 01 '18 at 02:01
  • You are trying to bind your express application to the same port that mysql is already running on. That is meant to be a "different port" which you connect your browser to. Use `app.listen(5000, 'localhost');` or some other port which is not in use by something else. – Neil Lunn Jun 01 '18 at 05:15
  • Thanks so much to Neil Lunn I got it connected now! By changing the port I was still not able to connect to the database until I ran the command in this answer: [link](https://stackoverflow.com/questions/50093144/mysql-8-0-client-does-not-support-authentication-protocol-requested-by-server) – Gabriel Garcia Jun 01 '18 at 14:41

0 Answers0