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

  • Home
  • SEARCH
  • 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 8105405
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T00:09:18+00:00 2026-06-06T00:09:18+00:00

I am currently working on a small personal multiplayer game project. I am using

  • 0

I am currently working on a small personal multiplayer game project. I am using node.js along with express.js, mongoose and socket.io. It is my first project with JavaScript, I come from a C/C++ background.

The question is:
Whether some kind of generic requiring is possible:
I have currently a models folder in my project root and all the mongoose models are in there,
they all look similar to this one:

function make(Schema, mongoose) {
var UserSchema = new Schema({
    name      : String
  , passwd    : String
  , is_online : Boolean
  , socket_id : Number
});
mongoose.model('User', UserSchema);
}
module.exports.make = make;

If I remember right, I found this approach somewhere on stackoverflow. Now when I am starting the node.js application, I have to connect to the database and then have to call all the make functions.

Is there a generic way to do that?

Somethink like this (pseudo-code):

models = require('./models/');
for each m in models do
{
     m.make(Schema, mongoose);
}
  • 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-06T00:09:19+00:00Added an answer on June 6, 2026 at 12:09 am

    I do it a little different:

    var UserSchema = new Schema({
        name      : String
      , passwd    : String
      , is_online : Boolean
      , socket_id : Number
    });
    module.exports = mongoose.model('User', UserSchema);
    

    Now I can require the model and use it right away like this:

    var userModel = require('models/user');
    userModel.find()//...
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am currently working on writing small game that is written in javascript, alot
I am currently working on a small project using RESTlet on Google App Engine/Java.
I'm currently working on a small web application using Visual Studio 2008 Express. I'm
I am currently working on a small sponsorship application(PHP/MySql) for my personal blog, and
I'm currently working on a small project where I'm loading 16bit wave files with
I am currently working on a small ASP.NET project involving authentication of users against
I'm currently working on a small short-lived project. But despite the size it's complicated
I am currently working on a small app engine project with python, jquery. I
I am currently working on a small side-project in MVC3. The goal is to
I'm currently working on a small project and would like some help on it.

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.