Each model is defined as its own module, which you export:
module.exports = function(sequelize, DataTypes){ return sequelize.define('Brand', { name: { type: DataTypes.STRING, unique: true, allowNull: false }, description: { type: DataTypes.TEXT, allowNull: false }, status: { type: DataTypes.INTEGER, unique: false, allowNull: true } }) };
Then just import the module when initializing Sequelize (and you can import many models here):
var Sequelize = require("sequelize"); var config = require("../../config/config.js"); var sequelize = new Sequelize(config.database, config.username, config.password, { dialect: config.dialect, host: config.host, port: config.port, omitNull: true, logging: false }); var Brand = require("./Brand").Brand;
You can read more about modules at http://nodejs.org/api/modules.htm , but the above example should get started.
Dan kohn
source share