Q:

Message.Create is not a function sequelize cli

I have installed mysql sequelize in my project then I creadted Message Model using sequelize command  which create model and migration file .I also given the db credentials in config.json file.Now I am trying to insert record in my db but getting this error here is my model file 

DO i need to make db connection explicitly or it auto picks the
  credential from config.json file to make connection ?

models/messages.js 
'use strict';
module.exports = (sequelize, DataTypes) => {
var Messages = sequelize.define('Messages', {
 room: DataTypes.STRING,
nickname: DataTypes.STRING,
message: DataTypes.STRING,
receiver: DataTypes.STRING
 }, {
classMethods: {
  associate: function(models) {
    // associations can be defined here
  }
}
});
 return Messages;
};

here is config.json file 
config/config.json
{
"development": {
"username": "root",
"password": "asad",
"database": "chat",
"host": "127.0.0.1",
"dialect": "mysql"
},
"test": {
"username": "root",
"password": null,
"database": "database_test",
"host": "127.0.0.1",
"dialect": "mysql"
 },
"production": {
"username": "root",
"password": null,
"database": "database_production",
"host": "127.0.0.1",
"dialect": "mysql"
 }
}

and here is my server file to save record
app.js file 
 var express = require('express');
 var router = express.Router();
  var app = express();
 var server = require('http').createServer(app);
 server.listen(4000);
 var Messages=require('../models/Messages.js');

router.post('/', function(req, res, next) {
  var a =req.body;

 Messages.create(a).then(() => {

  console.log('success ')

})
 })

A:

make sequelize connection instance and export it, please use config according to your environment 
const sql = new Sequelize(config.database, config.username, config.password, {
  host: config.host,
  dialect: config.dialect,
  pool: {
    max: 5,
    min: 0,
    idle: 10000
  },

});
module.export = sql;

In your app.js import sql instance and connect your db before starting your server.
var express = require('express');
var router = express.Router();
var app = express();
var server = require('http').createServer(app);
var sql = require(./sql);
sql.authenticate().then(()=>{
   server.listen(4000);
});

var Messages= sql.import('../models/Messages.js');

router.post('/', function(req, res, next) {
  var a =req.body;

 Messages.create(a).then(() => {

  console.log('success ')

})
})

