TypeError:无法读取未定义的属性“findAll”

我正在开发一个使用angularjs,nodejs和postgresql的web应用程序。 我在我的数据库中有两个表,一个用于库存,另一个用于客户端。 我结合我的index.js文件,在我的路线文件夹,其中两个表都有一个findAll函数。 当我把这两个表的引用index.js,一次只有一个工作。 这里是两个表使用的模板,包括findAll:

exports.getobjects = function(req, res) { models.Object.findAll().then(function(objectss){ res.json(objects); }); }; 

有没有人做了我想要做的事情? 更新:这里是整个index.js文件:

 /* * GET home page. */ var models = require("../models"); exports.index = function(req, res) { res.render('index', { title : 'title' }); }; /* clients */ exports.getclients = function(req, res) { models.Client.findAll().then(function(clients){ res.json(clients); }); }; exports.saveclients = function(req, res) { models.Client.create({ name: req.body.name, ssn: req.body.ssn, dln: req.body.dln, dls: req.body.dls, zip: req.body.zip, email: req.body.email, notes: req.body.notes, }).then(function(clients){ res.json(clients.dataValues); }).catch(function(error){ console.log("ops: " + error); res.status(500).json({ error: 'error' }); }); }; /*inventory*/ exports.getunits = function(req, res) { models.Unit.findAll().then(function(units){ res.json(units); }); }; exports.saveunits = function(req, res) { models.Unit.create({ name: req.body.text, quant: reg.body.quant }).then(function(units){ res.json(units.dataValues); }).catch(function(error){ console.log("ops: " + error); res.status(500).json({ error: 'error' }); }); }; 

你正在做错你的出口。 这是一个如何正确地做到这一点的例子。

比方说,我想出口2模块function这是一个简单的方法来实现它。

myModule.js

 module.exports = { awesomeMethod: function () { }, coolMethod: function () { } } 

现在要使用它,我会做以下

var myModule = require('./ myModule');

 myModule.awesomeMethod(); myModule.coolMethod();