Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8678571
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T20:45:17+00:00 2026-06-12T20:45:17+00:00

I have one module called UserProvider that looks like this var UserProvider = function(db)

  • 0

I have one module called UserProvider that looks like this

var UserProvider = function(db) { ... }
UserProvider.prototype.createUser = function(email, password, callback) { ... }
UserProvider.prototype.findUserByEmail = function(email, callback) { ... }
...
exports.UserProvider = UserProvider;

And another module called ModelProvider that looks like this

var UserProvider = require('./user').UserProvider;
var ModelProvider = function() {
    ...
    this.User = new UserProvider(db);
}
exports.ModelProvider = ModelProvider;

But the line this.User = new UserProvider(db); doesn’t allow me to access the UserProvider object in my main module that has included the ModelProvider module.

When I try to call this:

var ModelProvider = require('./model/model').ModelProvider;
var Model = new ModelProvider();

Model.User.findUserByEmail(email, function() {...});

It gives the following error:

TypeError: Object function Model(doc, fields, skipId) {
    if (!(this instanceof Model))
        return new Model(doc, fields, skipId);
    model.call(this, doc, fields, skipId);
} has no method 'findUserByEmail'

I’m assuming there is some JavaScript trickery that I am missing to expose this down?

Thanks!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T20:45:19+00:00Added an answer on June 12, 2026 at 8:45 pm

    What appears to be happening in this case and the cause of your error is that Model.User is actually not an instance of UserProvider but appears to point to a function called Model defined as…

    function Model(doc, fields, skipId) {
        if(!(this instanceof Model))
            return new Model(doc, fields, skipId);
        model.call(this, doc, fields, skipId);
    }
    

    Now this assignment could be happen at three places within your code…

    var Model = new ModelProvider();
    // Here sets Model.User
    Model.User.findUserByEmail(...);
    

    Or…

    function ModelProvider() {
        ...
        this.User = new UserProvider(db);
        // Here sets this.User
    }
    

    Or…

    function UserProvider(db) {
        // Here as a return statement
    }
    

    I would guess the latter is probably where the issue is happening.


    To be clear all of the following are possible in NodeJS…

    Importing a constructor from a module that didn’t necessarily contain it… To be clear you shouldn’t do this but it is possible to chain the exports so that a module exposes items from other modules it imports. You should import modules explicitly.

    module.js…

    var Something = require("./something").Something;
    exports.Something;
    

    main.js…

    var Something = require("./module").Something;
    

    Repeat do not do this. Instead include what you need from the module that owns it and don’t export anything the module doesn’t own. I’ve only included this example to clarify what exports and require can do.


    Access an instance created in another module… You can export the instance via the exports object as you would a constructor.

    module.js…

    function MySomething() {
        //...
    }
    exports.mySomething = new MySomething();
    

    main.js…

    var mySomething = require("./module").mySomething;
    

    Through an instance of an imported constructor, access an instance of a constructor that it has also imported… You can expose it through the this scope in which case it will be accessible through the public members of the instance you create of the constructor you imported.

    module.js…

    var Something = require("./something").Something;
    function MySomething() {
        this.something = new Something();
    }
    exports.MySomething = MySomething;
    

    main.js…

    var MySomething = require("./module").MySomething;
    var mySomething = new MySomething();
    mySomething.something;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have one Python module that can be called by a CGI script (passing
I have an ASP project, in that one module is a separate MVC project.
I'm working on a Rails application. I have a Module called Animals. Inside this
Consider this scenario: I have a project with two modules and one common module
I have a module that builds an app called MyApp. I have another that
I have one project (called EJB server) that contains X-Doclet annotated EJB service and
I have a static Object called Module . One of the attributes for a
I have a symfony app that provides REST based services. I have one module
i have to get static information from one 'module' to another. I'm trying to
Scenario 1: I have one wrapper Perl script which uses another Perl module and

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.