O'Reilly logo

Web Development with MongoDB and NodeJS - Second Edition by Jason Krol, Bruno Joseph D'mello, Mithun Satheesh

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Adding the application code

Now, let's write the simple application code to test things out. This app is going to basically connect to our locally running MongoDB server, insert a few records as seed data, and then provide the output on whether or not the data was inserted properly into MongoDB.

You can download a Gist of the code via the URL: http://bit.ly/1JpT8QL.

Using your editor of choice, create a new file named app.js and save it to the application root, which is the testapp folder. Just copy the content of the above Gist on to the app.js file.

Understanding the code

Now, let's go through and explain what each section of the code is doing.

//require the mongoClient from mongodb module 
var MongoClient = require('mongodb').MongoClient;

The preceding ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required