I am new to node.js, trying to write a module, but I ran into a problem .. I am registering in a child module:

var User = require('./schema'); User.userIsExist = function(id) { User.findOne({id: id}), function(err, tester) { console.log(tester); } } module.exports = User; 

and mainly:

 var User = require('./model').User; if(User.userIsExist(userinfo.uid)) { // Авторизируемся } 

But at the output I get TypeError: User.userIsExist is not a function

what am I doing wrong?

    1 answer 1

    You are exporting an object that does not have a User property. And when you import, you access this property. It will be right like this

     var user = require('./model'); if(user.userIsExist(userinfo.uid)) { // Авторизируемся } 

    And it is better not to give variable names with a capital letter. Capitalized is usually called classes.