-1
I have this mistake and I couldn’t find any questions on Stackoverflow that would help me... the error is being generated provable because of a promise
Index.js
const path = require('path')
const app = express()
const port = process.env.PORT || 3000
const mysql = require('mysql')
const connection = mysql.createConnection({
host: 'HOST',
user: 'USER',
pass: 'PASS',
database: 'BD'
})
const dependencies = {
connection
}
const users = require('./routes/users')
app.use(express.static('public'))
app.get('/', (req, res) => res.render('home'))
app.use('/usuarios', users(dependencies))
//view engine
app.set('views', path.join(__dirname, 'views'))
app.set('view engine', 'ejs')
connection.connect(() => {
app.listen(port, () => console.log('Servidor no ar, porta:', +port))
})
Routes/users.js
const express = require('express')
const usersController = require('../controllers/users')
const usersRouter = ({ connection }) => {
const router = express.Router()
router.get('/', usersController.index.bind(null, connection))
return router
}
module.exports = usersRouter
Controllers/users.js
const users = require('../models/users')
const index = async(connection, req, res) => {
const results = await users.findAll(connection)
res.render('olá')
}
module.exports = {
index
}
Models/users.js
const findAll = (connection) => {
return new Promise((resolve, reject) => {
connection.query('select * from users', (err, results) => {
if(err){
reject(err)
}else{
resolve(results)
}
})
})
}
module.exports = {
findAll
}
Some kind soul to help me?! kkkkk
console.log(Connection) in the findAll method returns what?
– Marconi
o node não chega até o fim do método... 
subi o console.log 1 nível e mostrou isso no item _fatalError: { Error: getaddrinfo ENOTFOUND mysql.umbler.com:41890 mysql.umbler.com:41890:3306
 at GetAddrInfoReqWrap.onlookup [as oncomplete]
– Guilherme Moreira
Related: https://answall.com/questions/285695/erro-unhandledpromiserejectionwarning
– Luiz Felipe