Pessoal.. Segue o erro que obtenho ao dar o get em localhost:3000/produtos dando um console.log no erro:
{ Error: ER_ACCESS_DENIED_ERROR: Access denied for user 'root'@'localhost' (using password: YES)
at Handshake.Sequence._packetToError (C:\Users\lc\Desktop\Curso_NodeJS\casaDoCodigo\node_modules\mysql\lib\protocol\sequences\Sequence.js:52:14)
at Handshake.ErrorPacket (C:\Users\lc\Desktop\Curso_NodeJS\casaDoCodigo\node_modules\mysql\lib\protocol\sequences\Handshake.js:103:18)
at Protocol._parsePacket (C:\Users\lc\Desktop\Curso_NodeJS\casaDoCodigo\node_modules\mysql\lib\protocol\Protocol.js:280:23)
at Parser.write (C:\Users\lc\Desktop\Curso_NodeJS\casaDoCodigo\node_modules\mysql\lib\protocol\Parser.js:74:12)
at Protocol.write (C:\Users\lc\Desktop\Curso_NodeJS\casaDoCodigo\node_modules\mysql\lib\protocol\Protocol.js:39:16)
at Socket.<anonymous> (C:\Users\lc\Desktop\Curso_NodeJS\casaDoCodigo\node_modules\mysql\lib\Connection.js:109:28)
at emitOne (events.js:96:13)
at Socket.emit (events.js:188:7)
at readableAddChunk (_stream_readable.js:176:18)
at Socket.Readable.push (_stream_readable.js:134:10)
--------------------
at Protocol._enqueue (C:\Users\lc\Desktop\Curso_NodeJS\casaDoCodigo\node_modules\mysql\lib\protocol\Protocol.js:141:48)
at Protocol.handshake (C:\Users\lc\Desktop\Curso_NodeJS\casaDoCodigo\node_modules\mysql\lib\protocol\Protocol.js:52:41)
at Connection.connect (C:\Users\lc\Desktop\Curso_NodeJS\casaDoCodigo\node_modules\mysql\lib\Connection.js:136:18)
at Connection._implyConnect (C:\Users\lc\Desktop\Curso_NodeJS\casaDoCodigo\node_modules\mysql\lib\Connection.js:467:10)
at Connection.query (C:\Users\lc\Desktop\Curso_NodeJS\casaDoCodigo\node_modules\mysql\lib\Connection.js:212:8)
at ProdutosDAO.listarProdutos (C:\Users\lc\Desktop\Curso_NodeJS\casaDoCodigo\app\infra\ProdutosDAO.js:6:19)
at C:\Users\lc\Desktop\Curso_NodeJS\casaDoCodigo\app\routes\produtos.js:6:17
at Layer.handle [as handle_request] (C:\Users\lc\Desktop\Curso_NodeJS\casaDoCodigo\node_modules\express\lib\router\layer.js:95:5)
at next (C:\Users\lc\Desktop\Curso_NodeJS\casaDoCodigo\node_modules\express\lib\router\route.js:131:13)
at Route.dispatch (C:\Users\lc\Desktop\Curso_NodeJS\casaDoCodigo\node_modules\express\lib\router\route.js:112:3)
code: 'ER_ACCESS_DENIED_ERROR',
errno: 1045,
sqlState: '28000',
fatal: true }
A variavel de resultado esta vindo undefined
.
Ja criei outro usuario e o erro persiste!
Segue a minha connectionFactory
:
var mysql = require('mysql');
var createDBConnection = function() {
console.log('Estou conectado com o MySQL.');
return mysql.createConnection({
host: 'localhost',
user: 'root',
password: 'root',
database: 'casadocodigo_nodejs'
});
};
module.exports = function() {
console.log('Express-Load me chamando..');
return createDBConnection;
};
O package.json
está certinho com as dependencias.
Estranho que pelo console do MySQL realizo o select normalmente. =/