We now have a solid understanding of the most basic concepts of how MongoDB works, and it is high time we put them to good work by integrating MongoDB with Node.js. In this section, we will cover this process step-by-step, and see how we can interact with the MongoDB databases directly from within a running Node.js instance.
Before we start, please make sure that you have Node.js and Node Package Manager (NPM) installed on your system. Refer to Chapter 1, Setting Up Your Workspace, for the steps for your particular operating system.
Once you are set, start off by creating a basic project to experiment a bit with the MongoDB instance. Create a folder somewhere and call it MongoNode. Next, open a terminal (OS X/Linux) or the command prompt (Windows), navigate to this folder, and issue the following command:
npm init
This will launch an interactive wizard for the bootstrapping of a basic Node.js application. In the following code, we provide...