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
€20.98 €29.99
Paperback
€36.99
Subscription
Free Trial
Renews at €18.99p/m

What do you get with Print?

Product feature icon Instant access to your digital eBook copy whilst your Print order is Shipped
Product feature icon Paperback book shipped to your preferred address
Product feature icon Download this book in EPUB and PDF formats
Product feature icon Access this title in our online reader with advanced features
Product feature icon DRM FREE - Read whenever, wherever and however you want
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
Estimated delivery fee Deliver to Estonia

Premium delivery 7 - 10 business days

€25.95
(Includes tracking information)

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 Print?

Product feature icon Instant access to your digital eBook copy whilst your Print order is Shipped
Product feature icon Paperback book shipped to your preferred address
Product feature icon Download this book in EPUB and PDF formats
Product feature icon Access this title in our online reader with advanced features
Product feature icon DRM FREE - Read whenever, wherever and however you want
Estimated delivery fee Deliver to Estonia

Premium delivery 7 - 10 business days

€25.95
(Includes tracking information)

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
€18.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
€189.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
€264.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 120.97
Web Development with MongoDB and Node.js
€36.99
Node.js Design Patterns
€41.99
MEAN Web Development
€41.99
Total 120.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 the delivery time and cost of print book? Chevron down icon Chevron up icon

Shipping Details

USA:

'

Economy: Delivery to most addresses in the US within 10-15 business days

Premium: Trackable Delivery to most addresses in the US within 3-8 business days

UK:

Economy: Delivery to most addresses in the U.K. within 7-9 business days.
Shipments are not trackable

Premium: Trackable delivery to most addresses in the U.K. within 3-4 business days!
Add one extra business day for deliveries to Northern Ireland and Scottish Highlands and islands

EU:

Premium: Trackable delivery to most EU destinations within 4-9 business days.

Australia:

Economy: Can deliver to P. O. Boxes and private residences.
Trackable service with delivery to addresses in Australia only.
Delivery time ranges from 7-9 business days for VIC and 8-10 business days for Interstate metro
Delivery time is up to 15 business days for remote areas of WA, NT & QLD.

Premium: Delivery to addresses in Australia only
Trackable delivery to most P. O. Boxes and private residences in Australia within 4-5 days based on the distance to a destination following dispatch.

India:

Premium: Delivery to most Indian addresses within 5-6 business days

Rest of the World:

Premium: Countries in the American continent: Trackable delivery to most countries within 4-7 business days

Asia:

Premium: Delivery to most Asian addresses within 5-9 business days

Disclaimer:
All orders received before 5 PM U.K time would start printing from the next business day. So the estimated delivery times start from the next day as well. Orders received after 5 PM U.K time (in our internal systems) on a business day or anytime on the weekend will begin printing the second to next business day. For example, an order placed at 11 AM today will begin printing tomorrow, whereas an order placed at 9 PM tonight will begin printing the day after tomorrow.


Unfortunately, due to several restrictions, we are unable to ship to the following countries:

  1. Afghanistan
  2. American Samoa
  3. Belarus
  4. Brunei Darussalam
  5. Central African Republic
  6. The Democratic Republic of Congo
  7. Eritrea
  8. Guinea-bissau
  9. Iran
  10. Lebanon
  11. Libiya Arab Jamahriya
  12. Somalia
  13. Sudan
  14. Russian Federation
  15. Syrian Arab Republic
  16. Ukraine
  17. Venezuela
What is custom duty/charge? Chevron down icon Chevron up icon

Customs duty are charges levied on goods when they cross international borders. It is a tax that is imposed on imported goods. These duties are charged by special authorities and bodies created by local governments and are meant to protect local industries, economies, and businesses.

Do I have to pay customs charges for the print book order? Chevron down icon Chevron up icon

The orders shipped to the countries that are listed under EU27 will not bear custom charges. They are paid by Packt as part of the order.

List of EU27 countries: www.gov.uk/eu-eea:

A custom duty or localized taxes may be applicable on the shipment and would be charged by the recipient country outside of the EU27 which should be paid by the customer and these duties are not included in the shipping charges been charged on the order.

How do I know my custom duty charges? Chevron down icon Chevron up icon

The amount of duty payable varies greatly depending on the imported goods, the country of origin and several other factors like the total invoice amount or dimensions like weight, and other such criteria applicable in your country.

For example:

  • If you live in Mexico, and the declared value of your ordered items is over $ 50, for you to receive a package, you will have to pay additional import tax of 19% which will be $ 9.50 to the courier service.
  • Whereas if you live in Turkey, and the declared value of your ordered items is over € 22, for you to receive a package, you will have to pay additional import tax of 18% which will be € 3.96 to the courier service.
How can I cancel my order? Chevron down icon Chevron up icon

Cancellation Policy for Published Printed Books:

You can cancel any order within 1 hour of placing the order. Simply contact customercare@packt.com with your order details or payment transaction id. If your order has already started the shipment process, we will do our best to stop it. However, if it is already on the way to you then when you receive it, you can contact us at customercare@packt.com using the returns and refund process.

Please understand that Packt Publishing cannot provide refunds or cancel any order except for the cases described in our Return Policy (i.e. Packt Publishing agrees to replace your printed book because it arrives damaged or material defect in book), Packt Publishing will not accept returns.

What is your returns and refunds policy? Chevron down icon Chevron up icon

Return Policy:

We want you to be happy with your purchase from Packtpub.com. We will not hassle you with returning print books to us. If the print book you receive from us is incorrect, damaged, doesn't work or is unacceptably late, please contact Customer Relations Team on customercare@packt.com with the order number and issue details as explained below:

  1. If you ordered (eBook, Video or Print Book) incorrectly or accidentally, please contact Customer Relations Team on customercare@packt.com within one hour of placing the order and we will replace/refund you the item cost.
  2. Sadly, if your eBook or Video file is faulty or a fault occurs during the eBook or Video being made available to you, i.e. during download then you should contact Customer Relations Team within 14 days of purchase on customercare@packt.com who will be able to resolve this issue for you.
  3. You will have a choice of replacement or refund of the problem items.(damaged, defective or incorrect)
  4. Once Customer Care Team confirms that you will be refunded, you should receive the refund within 10 to 12 working days.
  5. If you are only requesting a refund of one book from a multiple order, then we will refund you the appropriate single item.
  6. Where the items were shipped under a free shipping offer, there will be no shipping costs to refund.

On the off chance your printed book arrives damaged, with book material defect, contact our Customer Relation Team on customercare@packt.com within 14 days of receipt of the book with appropriate evidence of damage and we will work with you to secure a replacement copy, if necessary. Please note that each printed book you order from us is individually made by Packt's professional book-printing partner which is on a print-on-demand basis.

What tax is charged? Chevron down icon Chevron up icon

Currently, no tax is charged on the purchase of any print book (subject to change based on the laws and regulations). A localized VAT fee is charged only to our European and UK customers on eBooks, Video and subscriptions that they buy. GST is charged to Indian customers for eBooks and video purchases.

What payment methods can I use? Chevron down icon Chevron up icon

You can pay with the following card types:

  1. Visa Debit
  2. Visa Credit
  3. MasterCard
  4. PayPal
What is the delivery time and cost of print books? Chevron down icon Chevron up icon

Shipping Details

USA:

'

Economy: Delivery to most addresses in the US within 10-15 business days

Premium: Trackable Delivery to most addresses in the US within 3-8 business days

UK:

Economy: Delivery to most addresses in the U.K. within 7-9 business days.
Shipments are not trackable

Premium: Trackable delivery to most addresses in the U.K. within 3-4 business days!
Add one extra business day for deliveries to Northern Ireland and Scottish Highlands and islands

EU:

Premium: Trackable delivery to most EU destinations within 4-9 business days.

Australia:

Economy: Can deliver to P. O. Boxes and private residences.
Trackable service with delivery to addresses in Australia only.
Delivery time ranges from 7-9 business days for VIC and 8-10 business days for Interstate metro
Delivery time is up to 15 business days for remote areas of WA, NT & QLD.

Premium: Delivery to addresses in Australia only
Trackable delivery to most P. O. Boxes and private residences in Australia within 4-5 days based on the distance to a destination following dispatch.

India:

Premium: Delivery to most Indian addresses within 5-6 business days

Rest of the World:

Premium: Countries in the American continent: Trackable delivery to most countries within 4-7 business days

Asia:

Premium: Delivery to most Asian addresses within 5-9 business days

Disclaimer:
All orders received before 5 PM U.K time would start printing from the next business day. So the estimated delivery times start from the next day as well. Orders received after 5 PM U.K time (in our internal systems) on a business day or anytime on the weekend will begin printing the second to next business day. For example, an order placed at 11 AM today will begin printing tomorrow, whereas an order placed at 9 PM tonight will begin printing the day after tomorrow.


Unfortunately, due to several restrictions, we are unable to ship to the following countries:

  1. Afghanistan
  2. American Samoa
  3. Belarus
  4. Brunei Darussalam
  5. Central African Republic
  6. The Democratic Republic of Congo
  7. Eritrea
  8. Guinea-bissau
  9. Iran
  10. Lebanon
  11. Libiya Arab Jamahriya
  12. Somalia
  13. Sudan
  14. Russian Federation
  15. Syrian Arab Republic
  16. Ukraine
  17. Venezuela