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 6565197
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T14:03:50+00:00 2026-05-25T14:03:50+00:00

I created my Schema ‘s in my models/mymodel.js file. I also have my models

  • 0

I created my Schema‘s in my models/mymodel.js file. I also have my models in there as well as my methods.

How do I export them into my routes?

  • 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-05-25T14:03:51+00:00Added an answer on May 25, 2026 at 2:03 pm
    // route.js
    var mongoose = require("mongoose");
    
    var Posts = mongoose.model("posts")
    ...
    

    Ensure that you set up a bootstrap mechanism that runs all your model files. Once that is done you should have called mongoose.model("name", Model) for a set of models.

    This has cached those models in mongoose internally. So you can just call mongoose.model("name") anywhere you want.

    The only thing that’s important is order of execution. The model & schemas need to be registered before you run your routes.

    This is as a simple as :

    // create app
    var app = express.createServer(...);
    // do stuff with app
    
    var files = fs.readdirSync("models");
    files.forEach(function(file) {
      require("models/" + file);
    });
    
    var routes = fs.readdirSync("routes");
    routes.forEach(function(route) {
      require("routes/" + route)(app);
    });
    
    app.listen(80);
    

    Note that normally readdirSync is evil but it’s ok to execute blocking calls at startup time (like require) before your listen to your server

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have created one Catalyst application and I have created Schema and Model using
I have created a schema as an agreed upon interface between our company and
I am using SQL Server 2008 R2, and I have created a schema Test
I have created an XML schema (foo.xsd) and used xjc to create my binding
I have created a forum board app, based on YAML schema found in 'real
Hi I have created a schema and the following pattern to check for email
i have generated the script and created the schema in my computer. now how
I have a few fields on a list that was created using a schema.
I have just rolled a custom configuration section, created an accompanying schema document for
i have created a table named Ord in SQlite and the schema is :

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.