0

I've a working script to connect and work with Sequelize on Node.js But now i'm trying to connect this to my MySQL database on XAMPP

MySQL Port on XAMPP: 3306

When i run node.js after i have configured the app.listen and the config of sequealize i get the following error

ERROR: listen EADDRINUSE :::3306

I've looked for but i didn't find much information about that, i don't know what i'm doing bad. Thanks you for every answer!

app.js

const express = require('express')
const bodyParser = require('body-parser')
const cors = require('cors')
const morgan = require('morgan')
const { sequelize } = require('./models')
const config = require('./config/config')

const app = express()
app.use(morgan('combined'))
app.use(bodyParser.json())
app.use(cors())

require('./routes')(app)

sequelize.sync()
  .then(() => {
    app.listen(config.db.options.port || 3306) // 8081 original
    console.log(`Server iniciado en puerto: ${config.db.options.port}`)
  })

config.js

module.exports = {
  db: {
    database: process.env.DB_NAME || 'intraenvios',
    user: process.env.DB_USER || 'root',
    password: process.env.DB_PASS || '',
    options: {
      dialect: process.env.DIALECT || 'mysql', // sqlite original
      host: process.env.HOST || 'localhost',
      storage: './intraenvios.sqlite',
      port: process.env.PORT || 3306 // 8081 original
    }
  }
}

EDIT: enter image description here

8
  • Check your mysql server running of which port @Natarr Commented Sep 24, 2018 at 3:26
  • 1
    @PrashantGupta I think it's running on 3306. Post updated, could you see the img and tell me if i'm misunderstanding something? Commented Sep 24, 2018 at 3:29
  • Your code is fine.Open CMD and try to login using this command mysql -u root -p then enter password @Natarr Commented Sep 24, 2018 at 3:34
  • I'm on windows and i've only installed MySQL through XAMPP. @PrashantGupta Commented Sep 24, 2018 at 3:35
  • Please Insure your mysql is running of port 3306. This error means your port is bind to other service or mysql is not running of other port @Natarr. There is option in xampp also to login mysql and you can open xampp ulr using this ` localhost/phpmyadmin` there you can check mysql running or not . Commented Sep 24, 2018 at 3:39

1 Answer 1

2

For to connect by xampp simply, i made this:

const sequelize = new Sequelize('test', 'root', '', {
  host: "127.0.0.1",
  dialect : 'mysql',
  operatorsAliases: false
});

sequelize.authenticate().then(function(){
      console.log("sucess");
    }).catch(function(error){
      console.log("error: "+error);
});

Obs: operatorsAliases: false - To fix deprecated message of sequelize

Good Fun :)

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.