Wednesday, 7 June 2017

Cannot read property 'sync' of undefined

I am following a tutorial on how to set up a basic mvc in Nodejs using the hapi server and a few other packages.

Tutorial: https://www.sitepoint.com/node-js-mvc-application/

Git for my project: https://github.com/christoph88/node-js-mvc-tut/

I have an error when I try to launch the server:

~/Projects/node-js-mvc-tut$ node server.js 
/home/christoph/Projects/node-js-mvc-tut/server.js:33
Models.sequelize.sync().then(() => {
^
TypeError: Cannot read property 'sync' of undefined
at Object.<anonymous> (/home/christoph/Projects/node-js-mvc-tut/server.js:33:17)
at Module._compile (module.js:569:30)
at Object.Module._extensions..js (module.js:580:10)
at Module.load (module.js:503:32)
at tryModuleLoad (module.js:466:12)
at Function.Module._load (module.js:458:3)
at Function.Module.runMain (module.js:605:10)
at startup (bootstrap_node.js:158:16)
at bootstrap_node.js:575:3

Model is defined within the requirements. I do not understand why sync is undefined. Sequelise is required within the lib/index.js file.

'use strict';

const Hapi = require('hapi');
const Hoek = require('hoek');
const Path = require('path');
const Settings = require('./settings');
const Routes = require('./lib/routes');
const Models = require('./lib/models/');

const server = new Hapi.Server();

server.connection({ port: Settings.port });

server.register([
    require('vision'),
    require('inert')
], (err) => {
  Hoek.assert(!err, err);

  server.views({
    engines: { pug: require('pug') },
    path: Path.join(__dirname, 'lib/views'),
    compileOptions: {
      pretty: false
    },
    isCached: Settings.env === 'production'
  });

  // Add routes
  server.route(Routes);
});

Models.sequelize.sync().then(() => {
  server.start((err) => {
    Hoek.assert(!err, err);
    console.log(`Server running at: ${server.info.uri}`);
  });
});

Can somebody help me with this? Would be great to get this running so I can try to adapt it to my needs.



via Christoph

No comments:

Post a Comment