The first step in implementing MongoDB access from your Node.js applications is to add the MongoDB driver to your application project. The MongoDB Node.js driver is the officially supported native Node.js driver for MongoDB. It has by far the best implementation and is sponsored by MongoDB.
Note
This book can’t cover everything about the driver. For additional information, I recommend looking at the documentation for the MongoDB Node.js driver at http://mongodb.github.io/node-mongodb-native/.
Thanks to the Node.js modular framework, adding the MongoDB Node.js driver to a project requires just a simple npm
command. From your project root directory, execute the following commands at a console prompt to install the correct version of the MongoDB Node.js driver and the Mongoose module:
npm install [email protected]
npm install [email protected]
A node_modules
directory is created if there isn’t already one, and the mongodb
driver module is installed under it. Once that is done, your Node.js application files will be able to use the require('mongodb')
command to access the mongodb
module functionality.