Arquivo dbConnectionFactory.js
var mysql = require('mysql');
function createDBConnection(){
return mysql.createConnection({
host:'localhost',
user:'root',
password:'root',
database:'casadocodigo_nodejs'
});
}
module.exports = function() {
return createDBConnection();
}
Fonte produto.js
module.exports = function(app){
app.get('/produtos',(req,res)=>{
var connection = app.infra.dbConnectionFactory().createDBConnection();
connection.query('select * from livros', (err, results)=>{
res.render('produtos/lista',{lista:results});
});
connection.end();
});
}
Arquivo express.js
var express = require('express');
var load = require('express-load');
module.exports = function(){
var app = express();
app.set('view engine', 'ejs');
app.set('views','./app/views');
load('routes',{cwd:'app'}).then('infra').into(app);
return app;
}
Arquivo app.js
var express = require('express');
var load = require('express-load');
module.exports = function(){
var app = express();
app.set('view engine', 'ejs');
app.set('views','./app/views');
load('routes',{cwd:'app'}).then('infra').into(app);
return app;
}
Estou executando a app mas estou recebendo o erro, já revisei várias vezes mas não consegui identificar o problema, alguem consegue me ajudar. Obrigado
TypeError: app.infra.dbConnectionFactory is not a function
at app.get (C:\Projetos\node\casadocodigo\app\routes\produtos.js:6:30)
at Layer.handle [as handle_request] (C:\Projetos\node\casadocodigo\node_modules\express\lib\router\layer.js:95:5)
at next (C:\Projetos\node\casadocodigo\node_modules\express\lib\router\route.js:137:13)
at Route.dispatch (C:\Projetos\node\casadocodigo\node_modules\express\lib\router\route.js:112:3)
at Layer.handle [as handle_request] (C:\Projetos\node\casadocodigo\node_modules\express\lib\router\layer.js:95:5)
at C:\Projetos\node\casadocodigo\node_modules\express\lib\router\index.js:281:22
at Function.process_params (C:\Projetos\node\casadocodigo\node_modules\express\lib\router\index.js:335:12)
at next (C:\Projetos\node\casadocodigo\node_modules\express\lib\router\index.js:275:10)
at expressInit (C:\Projetos\node\casadocodigo\node_modules\express\lib\middleware\init.js:40:5)
at Layer.handle [as handle_request] (C:\Projetos\node\casadocodigo\node_modules\express\lib\router\layer.js:95:5)