1
I have the following error when trying to create a table:
const Usuario = app.db.sequelize.define('user', {
Typeerror: Cannot read Property 'sequelize' of Undefined
My folder structure:
My configuration file ( server.js )
module.exports = function(){
var express = require("express");
var consign = require("consign");
var app = express();
consign({ cwd: "app" }).include("routes").then("config/db.js").then("controller").then("model").into(app);
return app;
}
My db.js
var sequelize = require("sequelize");
const db = new sequelize("william", "root", "root", { host: "localhost", dialect: "mysql", operatorsAliases: false });
module.exports = db;
My index.js
var app = require("./app/config/server")();
app.listen(3000, function(){
console.log("Rodando na porta 3000");
});
And my model is in trouble
module.exports = function(app){
const Usuario = app.db.sequelize.define('usuario', {
nome: Sequelize.STRING,
endereco: Sequelize.STRING
});
}
Note: I am using the express: 4.16.2, cosign: 0.1.6, mysql2: 1.5.1, sequelize: 4.32.3
try to change the injection of the consign where it is
then("config/db.js")
forthen("config")
– BrTkCa
@Lucascosta he enters an infinite loop.
– William
leaves the server.js at the root and not inside the config folder and changes the path used in index.js
– BrTkCa
@Lucascosta unfortunately the error persists the same.
– William
In your db.js, try placing module.Exports = {db: db}
– Edudjr