Book Image

Web Development with MongoDB and Node.js

By : Jason Krol
Book Image

Web Development with MongoDB and Node.js

By: Jason Krol

Overview of this book

This book is designed for developers of any skill level that want to get up and running using Node.js and MongoDB to build full featured web applications. A basic understanding of JavaScript and HTML is the only requirement for this book.
Table of Contents (14 chapters)
12
12. Popular Node.js Web Frameworks
13
Index

Using MongoDB with Node


Before we officially implement MongoDB into our actual application, let's first take a look at some basic examples of connecting to a MongoDB server from within Node.js.

Create a new project folder to store some sample code to experiment with. I'll call my folder mongotest. Inside this folder, create a new file called test.js and in this file we will play around with some code to test how to connect to MongoDB and how to insert and retrieve some data. The first thing we need to do in order to connect to a MongoDB server from node is to require a mongodb module.

To get started, change directories into the new mongotest folder and install the mongodb module using npm:

$ cd mongotest
$ npm install mongodb

Note

Don't be confused by the module's name. The mongodb npm module isn't MongoDB itself, but rather a third-party npm module that facilitates communicating to a MongoDB server from within Node.js. Also, because this is just a sample project to experiment with, we don...