Book Image

Learning Node.js for Mobile Application Development

Book Image

Learning Node.js for Mobile Application Development

Overview of this book

Table of Contents (21 chapters)
Learning Node.js for Mobile Application Development
Credits
About the Authors
About the Reviewers
www.PacktPub.com
Preface
14
Creating an E-Commerce Application Using the Ionic Framework
Index

Connecting MongoDB and Node.js


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.

Setting up a basic project

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...