Thursday, 8 June 2017

Express-load 'models' undefined

I use express-load to load my files. However, I get this error inside my controller. What to do?

server.js

load('models')
    .then('controllers')
    .then('routes')
    .into(app);  

models/visitor.js

import mongoose from 'mongoose';

module.exports = function (app) {
  let Schema = new mongoose.Schema({
    name: { type: String, required: true },
    email: { type: String, required: true },
    phone: { type: String, required: true },
    createdAt: { type: Date, 'default': Date.now},
    updatedAt: { type: Date, 'default': Date.now}
  });

return mongoose.model('Visitor', Schema, 'visitors');

};

controllers/visitor.js

module.exports = function (app) {

  let Visitor = app.models.visitor;

  let controller = {
    index:(req, res) =>{
        res.json('ok');
    },
  };

  return controller;
};

Error received: TypeError: Cannot read property 'models' of undefined



via Eduardo Bennertz

No comments:

Post a Comment