ForestAdmin / lumber

Install Forest Admin in minutes.
https://www.forestadmin.com
MIT License
2.08k stars 106 forks source link

(node:89175) UnhandledPromiseRejectionWarning: SequelizeAccessDeniedError: Access denied for user 'samplebloguser'@'localhost' (using password: YES) at ConnectionManager.connect #460

Closed rhythm98 closed 4 years ago

rhythm98 commented 4 years ago

Exact Error

[Running] node "/home/rhythm/Desktop/docs/Projects/Best-Practices-Node.js-Project-master/src/run.js" (node:89175) UnhandledPromiseRejectionWarning: SequelizeAccessDeniedError: Access denied for user 'samplebloguser'@'localhost' (using password: YES) at ConnectionManager.connect (/home/rhythm/Desktop/docs/Projects/Best-Practices-Node.js-Project-master/node_modules/sequelize/lib/dialects/mysql/connection-manager.js:118:17) at processTicksAndRejections (internal/process/task_queues.js:97:5) (node:89175) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 1) (node:89175) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.

[Done] exited with code=0 in 1.146 seconds`

File Structure:

node_modules

src

models

db.js

run.js

server.js

Server.js

const express = require('express')

const path = require('path')
const e = require('express')

const app = express()

app.use('/', express.static(path.join(__dirname, '../public')))
app.use(express.json())
app.use(express.urlencoded({ extended: true }))

app.get('/', (req, res) => res.send('Hello World'))

// app.listen(2929, () => {
//   console.log('Server started on http://localhost:2929')
// })

module.exports = {
  app
}

db.js

const Sequelize = require('sequelize')
const { DataTypes } = Sequelize

const db = new Sequelize(
  'sampleblogdb', 'samplebloguser', 'sampleblogpass',
  {
    dialect: 'mysql',
    host: 'localhost'
  }
)
module.exports = {
  db
}

run.js

const { app } = require('./server')
const { db } = require('./models/db')
const log = require('debug')('app:run')

async function run () {
  await db.sync()
  log('Database is ready.')
  app.listen(2929, () => {
    log('Server started on http://localhost:2929')
  })
}
run()

I have installed community-mysql-server (with no root user password) on Fedora 32 machine

create database sampleblogdb;
create user 'samplebloguser'@'localhost' identified by 'Sampleblogpass@1234';
grant all privileges on sampleblogdb.* to 'samplebloguser'@'localhost';
flush privileges;

package.json

{
  "name": "best-practices",
  "version": "1.0.0",
  "description": "A project that showcases best practices for organising a nodejs project.",
  "main": "src/run.js",
  "scripts": {
    "start": "node src/run.js",
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "author": "Rhythm Agrawal",
  "license": "ISC",
  "dependencies": {
    "express": "^4.17.1",
    "express-hbs": "^2.3.4",
    "mysql2": "^2.1.0",
    "sequelize": "^6.3.4"
  },
  "devDependencies": {
    "debug": "^4.1.1",
    "eslint": "^7.6.0",
    "eslint-config-standard": "^14.1.1",
    "eslint-plugin-import": "^2.22.0",
    "eslint-plugin-node": "^11.1.0",
    "eslint-plugin-promise": "^4.2.1",
    "eslint-plugin-standard": "^4.0.1"
  }
}
rhythm98 commented 4 years ago

Sorted