What does require() do when the required file doesn't export anything? What's the right way to set up mongoose+express?

I'm looking at this simple to-do app example using express.js+mongoose (on github: https://github.com/dreamerslab/express-todo-example). In db.js file it defines the schema and makes a connection to the mongodb:

var mongoose = require( 'mongoose' );
var Schema   = mongoose.Schema;
var Todo = new Schema({
user_id    : String,
content    : String,
updated_at : Date
});
mongoose.model( 'Todo', Todo );
mongoose.connect( 'mongodb://localhost/express-todo' );

But it does not export anything. Yet in the app.'s file the db.js file is required like this:

// mongoose setup
require( './db' );

without assigning it to any variable.

So here comes the part that I don't understand: in the /routes/index.js file, you can use the model and schema simply by requiring mongoose like this

var mongoose = require( 'mongoose' );
var Todo     = mongoose.model( 'Todo' );
Todo.find(...)
...

So how does index.js figure out what goes in Todo model since the mongoose instance is NOT passed into it but re-required in it.

Besides, what is the proper way to setup the structure if I want to separate my schema into different files, e.g. having todo.js, user.js, and etc. Should I simply require the schema file in the db.js before making the connection?

Thanks in advance!

Structure of the to-do app:

todo
|-- node_modules
|   |-- ejs
|   |-- express
|   `-- mongoose
|
|-- public
|   |-- images
|   |-- javascripts
|   `-- stylesheets
|       |-- style.css
|
|-- routes
|   `-- index.js
|
|-- views
|   |-- index.ejs
|   `-- layout.ejs
|
|-- .gitignore
|
|-- app.js
|
`-- package.json

// mongoose setup
require( './db' );

That code just causes the db.js module to run, which is all that is needed in this case. Most modules will export something, but in this case the top-level code just needs to run so there's no need to export anything.

As for how mongoose allows you to define models in one file and use them in another, it uses a somewhat sophisticated approach of returning a singleton instance when required. See this line of code:

module.exports = exports = new Mongoose;

So that means what you get back from require('mongoose') is a globally-shared instance of Mongoose that has state keeping track of all the models defined. It is a bit "magic" in my opinion, but that's how it works. You could also create your own instance of Mongoose if you wanted to avoid that pattern.