title: How to separate the code into separate files?
body: <p>Code from official site:</p>
  
  <pre><code>const mongoose = require('mongoose');
  mongoose.connect('mongodb://localhost/test');
  
  const Cat = mongoose.model('Cat', { name: String });
  
  const kitty = new Cat({ name: 'Zildjian' });
  kitty.save().then(() =&gt; console.log('meow'));
  </code></pre>
  
  <p>I would like to separate the code into separate files:</p>
  
  <pre><code>/models/cat.js
  /db.js
  /index.js
  </code></pre>
  
  <p>In db.js:</p>
  
  <pre><code>const mongoose = require('mongoose');
  mongoose.connect('mongodb://localhost/test');
  module.exports = mongoose;
  </code></pre>
  
  <p>In models/cat.js:</p>
  
  <pre><code>const mongoose = require('mongoose');
  const Cat = mongoose.model('Cat', { name: String });
  module.exports = Cat;
  </code></pre>
  
  <p>And in index.js:</p>
  
  <pre><code>const Cat = require('./models/cat');
  const kitty = new Cat({ name: 'Zildjian' });
  kitty.save().then(() =&gt; console.log('meow'));
  </code></pre>
  
  <p>index.js is the starting file for my application, but I do not require the db.js file to it, because I don't know what for... index.js doesn't use constant mongoose, so how can I make the whole application use my connection from the db.js file?</p>