Beto de Castro Moreira

51%
Flag icon
//'db.js' module module.exports = new Database('my-app-db'); By simply exporting a new instance of our database, we can already assume that within the current package (which can easily be the entire code of our application), we are going to have only one instance of the db module. This is possible because, as we know, Node.js will cache the module after the first invocation of require(), making sure to not execute it again at any subsequent invocation, returning instead the cached instance.
Node.js Design Patterns: Master a series of patterns and techniques to create modular, scalable, and efficient applications
Rate this book
Clear rating
Open Preview