Javascript TypeError:无法读取属性';findAll';未定义的

Javascript TypeError:无法读取属性';findAll';未定义的,javascript,angularjs,node.js,postgresql,Javascript,Angularjs,Node.js,Postgresql,我正在开发一个使用angularjs、nodejs和postgresql的web应用程序。我的数据库中有两个表,一个用于库存,另一个用于客户端。我在routes文件夹中合并了index.js文件,其中两个表都有findAll函数。当我将表的两个引用放在index.js中时,一次只有一个有效。以下是两个表使用的模板,其中包括findAll: exports.getobjects = function(req, res) { models.Object.findAll().then(function

我正在开发一个使用angularjs、nodejs和postgresql的web应用程序。我的数据库中有两个表,一个用于库存,另一个用于客户端。我在routes文件夹中合并了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个函数,这是一个简单的实现方法

myModule.js

module.exports = {
    awesomeMethod: function () {

    },
    coolMethod: function () {

    }
}
现在要使用它,我将执行以下操作

var myModule=require('./myModule')


您可以包含index.js代码吗?我注意到的一件事是objectss(2 ss)正在被传递到回调方法中,但是您正在访问对象(1 s),这些对象将不会被定义抱歉,这是一个输入错误,不是在我的代码中!我将发布index.js,尽管您的导出语法实际上还不错
module
是全局的,doing
exports.foo=function(){}
是有效的。也就是说,从你的复制代码来看,完全不清楚什么地方出了问题。你能不能把复制过程减少到几行,然后公布你得到的实际错误?好的,我试着在index.js中实现它,现在我得到一个syntaxerror,声明clientMethod=function(){是一个无效的速记属性initializer它应该是clientMethod:function()。将=替换为:我明白了,我也尝试过这一点,但得到的错误是:function()是一个意外标记,在第一个标记下方有一个向上箭头(
myModule.awesomeMethod();
myModule.coolMethod();