Error creating a table with sequelize "TypeError: Can not read property 'sequelize' of undefined"

1

I'm having the following error when trying to create a table:

  

const User = app.db.sequelize.define ('user', {

     

TypeError: Can not read property 'sequelize' of undefined

My folder structure:

Myconfigurationfile(server.js)

module.exports=function(){varexpress=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 that is in trouble

module.exports = function(app){
    const Usuario = app.db.sequelize.define('usuario', {
        nome: Sequelize.STRING,
        endereco: Sequelize.STRING
    });
}

Note: I'm using the      express: 4.16.2,      cosign: 0.1.6,      mysql2: 1.5.1,      sequelize: 4.32.3

    
asked by anonymous 06.02.2018 / 15:50

0 answers