Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
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 eBook?

Product feature icon Instant access to your Digital eBook purchase
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
OR
Modal Close icon
Payment Processing...
tick Completed

Billing Address

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 : 9781783987313
Languages :
Tools :

What do you get with eBook?

Product feature icon Instant access to your Digital eBook purchase
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
OR
Modal Close icon
Payment Processing...
tick Completed

Billing Address

Product Details

Publication date : Sep 25, 2014
Length: 294 pages
Edition : 1st
Language : English
ISBN-13 : 9781783987313
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
Banner background image

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

How do I buy and download an eBook? Chevron down icon Chevron up icon

Where there is an eBook version of a title available, you can buy it from the book details for that title. Add either the standalone eBook or the eBook and print book bundle to your shopping cart. Your eBook will show in your cart as a product on its own. After completing checkout and payment in the normal way, you will receive your receipt on the screen containing a link to a personalised PDF download file. This link will remain active for 30 days. You can download backup copies of the file by logging in to your account at any time.

If you already have Adobe reader installed, then clicking on the link will download and open the PDF file directly. If you don't, then save the PDF file on your machine and download the Reader to view it.

Please Note: Packt eBooks are non-returnable and non-refundable.

Packt eBook and Licensing When you buy an eBook from Packt Publishing, completing your purchase means you accept the terms of our licence agreement. Please read the full text of the agreement. In it we have tried to balance the need for the ebook to be usable for you the reader with our needs to protect the rights of us as Publishers and of our authors. In summary, the agreement says:

  • You may make copies of your eBook for your own use onto any machine
  • You may not pass copies of the eBook on to anyone else
How can I make a purchase on your website? Chevron down icon Chevron up icon

If you want to purchase a video course, eBook or Bundle (Print+eBook) please follow below steps:

  1. Register on our website using your email address and the password.
  2. Search for the title by name or ISBN using the search option.
  3. Select the title you want to purchase.
  4. Choose the format you wish to purchase the title in; if you order the Print Book, you get a free eBook copy of the same title. 
  5. Proceed with the checkout process (payment to be made using Credit Card, Debit Cart, or PayPal)
Where can I access support around an eBook? Chevron down icon Chevron up icon
  • If you experience a problem with using or installing Adobe Reader, the contact Adobe directly.
  • To view the errata for the book, see www.packtpub.com/support and view the pages for the title you have.
  • To view your account details or to download a new copy of the book go to www.packtpub.com/account
  • To contact us directly if a problem is not resolved, use www.packtpub.com/contact-us
What eBook formats do Packt support? Chevron down icon Chevron up icon

Our eBooks are currently available in a variety of formats such as PDF and ePubs. In the future, this may well change with trends and development in technology, but please note that our PDFs are not Adobe eBook Reader format, which has greater restrictions on security.

You will need to use Adobe Reader v9 or later in order to read Packt's PDF eBooks.

What are the benefits of eBooks? Chevron down icon Chevron up icon
  • You can get the information you need immediately
  • You can easily take them with you on a laptop
  • You can download them an unlimited number of times
  • You can print them out
  • They are copy-paste enabled
  • They are searchable
  • There is no password protection
  • They are lower price than print
  • They save resources and space
What is an eBook? Chevron down icon Chevron up icon

Packt eBooks are a complete electronic version of the print edition, available in PDF and ePub formats. Every piece of content down to the page numbering is the same. Because we save the costs of printing and shipping the book to you, we are able to offer eBooks at a lower cost than print editions.

When you have purchased an eBook, simply login to your account and click on the link in Your Download Area. We recommend you saving the file to your hard drive before opening it.

For optimal viewing of our eBooks, we recommend you download and install the free Adobe Reader version 9.