Skip to content

Instantly share code, notes, and snippets.

@bendrucker
Created February 20, 2014 21:24
Show Gist options
  • Save bendrucker/9123492 to your computer and use it in GitHub Desktop.
Save bendrucker/9123492 to your computer and use it in GitHub Desktop.
Initializing databases with Bookshelf
var i = 0;
module.exports = ++i;
require('./a'); // 1
require('./a'); // 1
require('./a'); // 1
var Bookshelf = require('bookshelf');
module.exports = Bookshelf.initialize({
client: 'pg',
connection: {
host: 'localhost',
user: 'Ben',
database: 'valet_io_auction'
}
});
@bendrucker
Copy link
Author

a.js and b.js are an illustration of how module caching works in Node. Once a particular module has been required, its value will be cached for any future requires in the same context, including from other files.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment