Search icon CANCEL
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Conferences
Free Learning
Arrow right icon
Web Development with MongoDB and Node.js
Web Development with MongoDB and Node.js

Web Development with MongoDB and Node.js: Build an interactive and full-featured web application from scratch using Node.js and MongoDB

eBook
$19.99 $28.99
Paperback
$48.99
Subscription
Free Trial
Renews at $19.99p/m

What do you get with a Packt Subscription?

Free for first 7 days. $19.99 p/m after that. Cancel any time!
Product feature icon Unlimited ad-free access to the largest independent learning library in tech. Access this title and thousands more!
Product feature icon 50+ new titles added per month, including many first-to-market concepts and exclusive early access to books as they are being written.
Product feature icon Innovative learning tools, including AI book assistants, code context explainers, and text-to-speech.
Product feature icon Thousands of reference materials covering every tech concept you need to stay up to date.
Subscribe now
View plans & pricing
Table of content icon View table of contents Preview book icon Preview Book

Web Development with MongoDB and Node.js

Chapter 2. Getting Up and Running

The first thing you need to take care of is to make sure your development environment is equipped with the necessary requirements in order for you to use both Node and MongoDB while launching the apps you write.

In this chapter, we will cover the following topics:

  • Installing and testing Node.js
  • Installing, configuring, and testing MongoDB
  • Writing and launching a simple app

Environment assumptions and requirements

For the remainder of this book, I will assume that you are using either a Mac with OS X, Linux, or Windows 7 or 8. You will also need superuser and/or administrator privileges on the computer, as you will be installing the Node and MongoDB server software. The code and examples after this chapter will all be OS agnostic and should work in any environment, assuming you have taken the steps I outline here so that you are prepared ahead of time.

You will need a good text editor to write and edit the code. Any editor of your liking will do. Personally, I am a huge fan of Sublime Text 3 (http://sublimetext.com). It is a simple, lightweight editor that has great color-coding syntax support. However, its true power comes from the unlimited plugins made available by other developers. There is literally a plugin for everything in Sublime! VI and Notepad are also good options if you want to stay super lightweight.

Finally, you're going to need access to...

Installing Node.js

Node.js can be easily installed by visiting the official Node website and accessing the Downloads section at http://nodejs.org/download/.

Once there, be sure to download the correct version depending on your OS and CPU (32 bit or 64 bit).

Mac OS X installation instructions

To determine which version of Node you want to download, you first need to determine your processor type: 32 or 64 bit. You can do this by executing the following command from a terminal:

$ sysctl hw | grep 64bit
hw.cpu64bit_capable: 1

If you get 1 in the response, then you are running a 64-bit CPU. If the response is 0, then you are running the 32-bit version. Fortunately, there is a universal installer specifically for Mac available from the Node website; however, if you wanted to download the binary, at least now you know which to get.

Once the download is complete, double-click on the .pkg file, which will launch the Node installer (as shown in the following screenshot):

Mac OS X installation instructions

Proceeding through each step of...

Installing the MongoDB server

MongoDB can also be easily downloaded by visiting the official MongoDB website and accessing the Downloads section at http://www.mongodb.org/downloads.

Note

Depending on the version of MongoDB you downloaded, you will want to replace <version> in the following sections with the appropriate version number that matches your file.

Once there, be sure to download the correct version depending on your OS and CPU (32 or 64 bit). You should have determined this in the previous steps when you downloaded and installed Node. For Windows users, you can opt to download the MSI installer file, which will make installation much simpler.

Mac OS X installation instructions

After completing the download, open and extract the contents of the .tgz file. You will want to move the extracted contents to a /mongodb destination folder. You can do this either via the Finder or the command line, whichever you prefer.

Note

Alternatively, MongoDB can be very easily installed using Homebrew...

Writing your first app

Now that you have everything installed and confirmed that it's all working, you can write your first quick app that will use both Node and MongoDB. This will prove that your environment is good to go, and you're ready to get started. In addition, it will give you a brief taste of the world of Node and MongoDB development! Don't worry if a lot of the following is confusing or just doesn't make sense to you—it will all be made clear throughout the rest of the book!

Step one is to create a folder that you can work from while creating files and installing Node modules. From your home or development folder, execute the following commands:

$ mkdir testapp
$ cd testapp

The code

The first thing you need to do before you write any code is download any modules you plan to use with your app from npm. Since this is a basic app, you'll only need to use the MongoDB Node driver. You can easily install this by executing the following command:

(term_1)...

Summary

In this chapter, we took time to make sure your development environment was properly configured with both the Node runtime environment as well as the MongoDB server. After making sure both were properly installed, we wrote a basic app that utilized both technologies.

The app connected to a locally running MongoDB server, checked for the existence of a specific set of data, and if it wasn't found, sample records were inserted automatically. It then retrieved those same records and displayed them to the screen, which were sorted alphabetically.

Now that the tedious but necessary tasks of set up and installation are out of the way, we can move on to some fun and get started with learning! In the next chapter, we will review a primer on the JavaScript language and understand the basics of Node. Then, we will review basic Create, Read, Update, Delete (CRUD) operations with MongoDB using the mongo shell.

Left arrow icon Right arrow icon

Description

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.

What you will learn

  • Set up a development environment and install Node.js and MongoDB
  • Write and configure a web server using Node.js powered by the Express.js framework
  • Build dynamic HTML pages using the Handlebars template engine
  • Persist application data using MongoDB and Mongoose ODM
  • Create and consume RESTful APIs
  • Test your code using automated testing tools
  • Deploy to the cloud using services such as Heroku, Amazon Web Services, and Microsoft Azure
  • Explore Single Page Application frameworks to take your web applications to the next level

Product Details

Country selected
Publication date, Length, Edition, Language, ISBN-13
Publication date : Sep 25, 2014
Length: 294 pages
Edition : 1st
Language : English
ISBN-13 : 9781783987306
Languages :
Tools :

What do you get with a Packt Subscription?

Free for first 7 days. $19.99 p/m after that. Cancel any time!
Product feature icon Unlimited ad-free access to the largest independent learning library in tech. Access this title and thousands more!
Product feature icon 50+ new titles added per month, including many first-to-market concepts and exclusive early access to books as they are being written.
Product feature icon Innovative learning tools, including AI book assistants, code context explainers, and text-to-speech.
Product feature icon Thousands of reference materials covering every tech concept you need to stay up to date.
Subscribe now
View plans & pricing

Product Details

Publication date : Sep 25, 2014
Length: 294 pages
Edition : 1st
Language : English
ISBN-13 : 9781783987306
Languages :
Tools :

Packt Subscriptions

See our plans and pricing
Modal Close icon
$19.99 billed monthly
Feature tick icon Unlimited access to Packt's library of 7,000+ practical books and videos
Feature tick icon Constantly refreshed with 50+ new titles a month
Feature tick icon Exclusive Early access to books as they're written
Feature tick icon Solve problems while you work with advanced search and reference features
Feature tick icon Offline reading on the mobile app
Feature tick icon Simple pricing, no contract
$199.99 billed annually
Feature tick icon Unlimited access to Packt's library of 7,000+ practical books and videos
Feature tick icon Constantly refreshed with 50+ new titles a month
Feature tick icon Exclusive Early access to books as they're written
Feature tick icon Solve problems while you work with advanced search and reference features
Feature tick icon Offline reading on the mobile app
Feature tick icon Choose a DRM-free eBook or Video every month to keep
Feature tick icon PLUS own as many other DRM-free eBooks or Videos as you like for just $5 each
Feature tick icon Exclusive print discounts
$279.99 billed in 18 months
Feature tick icon Unlimited access to Packt's library of 7,000+ practical books and videos
Feature tick icon Constantly refreshed with 50+ new titles a month
Feature tick icon Exclusive Early access to books as they're written
Feature tick icon Solve problems while you work with advanced search and reference features
Feature tick icon Offline reading on the mobile app
Feature tick icon Choose a DRM-free eBook or Video every month to keep
Feature tick icon PLUS own as many other DRM-free eBooks or Videos as you like for just $5 each
Feature tick icon Exclusive print discounts

Frequently bought together


Stars icon
Total $ 158.97
Web Development with MongoDB and Node.js
$48.99
Node.js Design Patterns
$54.99
MEAN Web Development
$54.99
Total $ 158.97 Stars icon

Table of Contents

13 Chapters
1. Welcome to JavaScript in the Full Stack Chevron down icon Chevron up icon
2. Getting Up and Running Chevron down icon Chevron up icon
3. Node and MongoDB Basics Chevron down icon Chevron up icon
4. Writing an Express.js Server Chevron down icon Chevron up icon
5. Dynamic HTML with Handlebars Chevron down icon Chevron up icon
6. Controllers and View Models Chevron down icon Chevron up icon
7. Persisting Data with MongoDB Chevron down icon Chevron up icon
8. Creating a RESTful API Chevron down icon Chevron up icon
9. Testing Your Code Chevron down icon Chevron up icon
10. Deploying with Cloud-based Services Chevron down icon Chevron up icon
11. Single Page Applications with Popular Frontend Frameworks Chevron down icon Chevron up icon
12. Popular Node.js Web Frameworks Chevron down icon Chevron up icon
Index Chevron down icon Chevron up icon

Customer reviews

Top Reviews
Rating distribution
Full star icon Full star icon Full star icon Full star icon Empty star icon 4
(12 Ratings)
5 star 58.3%
4 star 16.7%
3 star 0%
2 star 16.7%
1 star 8.3%
Filter icon Filter
Top Reviews

Filter reviews by




Burak AKIN Oct 14, 2014
Full star icon Full star icon Full star icon Full star icon Full star icon 5
I am not a professional coder or programmer. My job is health related. I code as a hobby. This book is what you need to get into development with Mongo and Nodejs. The example application inside the book will form a nice real time app also. The concepts are very well explained without boring you. Even a person like me can understand and code everything.
Amazon Verified review Amazon
Amazon Customer Oct 07, 2014
Full star icon Full star icon Full star icon Full star icon Full star icon 5
This book is a quick read to get you quickly running building any web applications with a MongoDB backend. The examples are easy to follow and quick to convert to a real scenario web application. Many extras beyond teaching the node and mongo lesson.
Amazon Verified review Amazon
Airam Oct 29, 2014
Full star icon Full star icon Full star icon Full star icon Full star icon 5
Writing RESTful services in Nodejs can be as simple as glueing modules. Internet is plenty of Node.js middleware. To achieve so, you first need to learn the basics.It's better to have some previous knowledge of Javascript before reading this book as Web Development with MongoDB and Node.js has a tiny introduction to Javascript and Node.js.The book explains how to scaffold web applications through full coded examples. Middleware is the key of being highly productive and the book uses and explains the most well-known modules. You'll find out a big example split into several chapters that is a clone of a popular social image-sharing site that will show you things such as:Express: handle routing, middleware injection, ...Connect: a suite of middleware for multiple things. In the book Connect is used to deal with json, cookies, logging, parsing, encoding, HTTP method support, handling errors ...Handlebars: apart from explaining the basics of this template engine, it also shows how to build html layouts, partial views which prevent code duplication and helpers used for injecting functions at the time of rendering.And all this is wired up with MongoDB which is a NoSQL database. You'll learn the really basics of CRUD operations over Mongo (Create, Retrieve, Update and Delete). But Mongo is such simple that it really doesn't need further explanation other than seeing the API definition. This makes the book swift and faster to read. As it's already a tradition with Mongo and Javascript, it also involves Mongoose. Mongoose introduces schemas and models, that is to say built-in types, field restrictions and validation.The book culminates with four miscellaneous chapters. A chapter dedicated to testing using Behavior Driven Development (Mocha, Chai.js, Sinon.js, Proxyquire). Another chapter that gathers some web services (like Heroku, Amazon, Digital Ocean, Nodejitsu and Microsoft Azure) and tells how to deploy your nodejs web-apps. And finally, the last two chapters reviews front-end frameworks like: Backbone.js, Ember.js, Angular.js; and Node.js frameworks like Meteor, Sails, hapi, Koa or Flatiron.At the end of the book you will be more likely to start developing your own RESTful services as Node.js makes things simple and this book covers really common problems.You can get your copy of Web Development with MongoDB and Node.js right here!
Amazon Verified review Amazon
Steven Aug 09, 2015
Full star icon Full star icon Full star icon Full star icon Full star icon 5
Jason is a MEAN expert! Great real world examples and spoken in a language that anyone can understand. Highly recommend this book to anyone who is spiking the Mongo/Express/Angular/Node stack to build engaging single page apps in JS.
Amazon Verified review Amazon
Sergiy Pylypets Oct 20, 2014
Full star icon Full star icon Full star icon Full star icon Full star icon 5
This book contains hands-on instructions for getting started with development of complete interactive Web sites using up-to-day Web technologies. It empowers readers with practical knowledge of Node.js and MongoDB. The first chapter describes new concepts of Web development, which were introduced with Node.js. From chapter 4, Writing an Express.js Server, we are guided to create a sample Web application, which includes all main functionality of real-world applications, based on the usage of Express.js Web framework. Chapter 9, Testing Your Code, introduces the tools and techniques to write automated tests for Node.js code. Chapter 10, Deploying with Cloud-based Services, provides detailed instructions for Cloud-based deployment and hosting of Web applications. In chapter 12, Popular Node.js Web Frameworks, author reviews other Web frameworks, including recently-emerged ones, and analyzes their advantages, drawbacks and cases of usage. The book is written by clear and concise language. The content includes a lot of code fragments, schemes, and screenshots. Each chapter ends with Summary section, which recapitulates all the main topics of the chapter. There are several reminder sections, like A JavaScript Primer, which recalls JavaScript basics, or What is an API, which discusses API development concepts. All chapters include links to additional information resources. For all main technologies being discussed, detailed step-by-step installation instructions are provided for Windows, Mac OS, and Linux environment, which greatly stimulate readers to download and try all the stuff. I think that this book can be useful for all Web developers, who want to use modern technologies for creating powerful and scalable Web applications.
Amazon Verified review Amazon
Get free access to Packt library with over 7500+ books and video courses for 7 days!
Start Free Trial

FAQs

What is included in a Packt subscription? Chevron down icon Chevron up icon

A subscription provides you with full access to view all Packt and licnesed content online, this includes exclusive access to Early Access titles. Depending on the tier chosen you can also earn credits and discounts to use for owning content

How can I cancel my subscription? Chevron down icon Chevron up icon

To cancel your subscription with us simply go to the account page - found in the top right of the page or at https://subscription.packtpub.com/my-account/subscription - From here you will see the ‘cancel subscription’ button in the grey box with your subscription information in.

What are credits? Chevron down icon Chevron up icon

Credits can be earned from reading 40 section of any title within the payment cycle - a month starting from the day of subscription payment. You also earn a Credit every month if you subscribe to our annual or 18 month plans. Credits can be used to buy books DRM free, the same way that you would pay for a book. Your credits can be found in the subscription homepage - subscription.packtpub.com - clicking on ‘the my’ library dropdown and selecting ‘credits’.

What happens if an Early Access Course is cancelled? Chevron down icon Chevron up icon

Projects are rarely cancelled, but sometimes it's unavoidable. If an Early Access course is cancelled or excessively delayed, you can exchange your purchase for another course. For further details, please contact us here.

Where can I send feedback about an Early Access title? Chevron down icon Chevron up icon

If you have any feedback about the product you're reading, or Early Access in general, then please fill out a contact form here and we'll make sure the feedback gets to the right team. 

Can I download the code files for Early Access titles? Chevron down icon Chevron up icon

We try to ensure that all books in Early Access have code available to use, download, and fork on GitHub. This helps us be more agile in the development of the book, and helps keep the often changing code base of new versions and new technologies as up to date as possible. Unfortunately, however, there will be rare cases when it is not possible for us to have downloadable code samples available until publication.

When we publish the book, the code files will also be available to download from the Packt website.

How accurate is the publication date? Chevron down icon Chevron up icon

The publication date is as accurate as we can be at any point in the project. Unfortunately, delays can happen. Often those delays are out of our control, such as changes to the technology code base or delays in the tech release. We do our best to give you an accurate estimate of the publication date at any given time, and as more chapters are delivered, the more accurate the delivery date will become.

How will I know when new chapters are ready? Chevron down icon Chevron up icon

We'll let you know every time there has been an update to a course that you've bought in Early Access. You'll get an email to let you know there has been a new chapter, or a change to a previous chapter. The new chapters are automatically added to your account, so you can also check back there any time you're ready and download or read them online.

I am a Packt subscriber, do I get Early Access? Chevron down icon Chevron up icon

Yes, all Early Access content is fully available through your subscription. You will need to have a paid for or active trial subscription in order to access all titles.

How is Early Access delivered? Chevron down icon Chevron up icon

Early Access is currently only available as a PDF or through our online reader. As we make changes or add new chapters, the files in your Packt account will be updated so you can download them again or view them online immediately.

How do I buy Early Access content? Chevron down icon Chevron up icon

Early Access is a way of us getting our content to you quicker, but the method of buying the Early Access course is still the same. Just find the course you want to buy, go through the check-out steps, and you’ll get a confirmation email from us with information and a link to the relevant Early Access courses.

What is Early Access? Chevron down icon Chevron up icon

Keeping up to date with the latest technology is difficult; new versions, new frameworks, new techniques. This feature gives you a head-start to our content, as it's being created. With Early Access you'll receive each chapter as it's written, and get regular updates throughout the product's development, as well as the final course as soon as it's ready.We created Early Access as a means of giving you the information you need, as soon as it's available. As we go through the process of developing a course, 99% of it can be ready but we can't publish until that last 1% falls in to place. Early Access helps to unlock the potential of our content early, to help you start your learning when you need it most. You not only get access to every chapter as it's delivered, edited, and updated, but you'll also get the finalized, DRM-free product to download in any format you want when it's published. As a member of Packt, you'll also be eligible for our exclusive offers, including a free course every day, and discounts on new and popular titles.