Search icon CANCEL
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Conferences
Free Learning
Arrow right icon
MEAN Web Development
MEAN Web Development

MEAN Web Development: Master real-time MEAN web application development and learn how to construct a MEAN application using a combination of MongoDB, Express, AngularJS, and Node.js

eBook
R$80 R$245.99
Paperback
R$306.99
Subscription
Free Trial
Renews at R$50p/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
Table of content icon View table of contents Preview book icon Preview Book

MEAN Web Development

Chapter 2. Getting Started with Node.js

In the previous chapter, you set up your environment and discovered the basic development principles of Node.js. This chapter will cover the proper way of building your first Node.js web application. You'll go through the basics of JavaScript event-driven nature and how to utilize it to build Node.js applications. You'll also learn about the Node.js module system and how to build your first Node.js web application. You'll then proceed to the Connect module and learn about its powerful middleware approach. By the end of this chapter, you'll know how to use Connect and Node.js to build simple yet powerful web applications. We'll cover the following topics:

  • Introduction to Node.js
  • JavaScript closures and event-driven programming
  • Node.js event-driven web development
  • CommonJS modules and the Node.js module system
  • Introduction to the Connect web framework
  • Connect's middleware pattern

Introduction to Node.js

At JSConf EU 2009, a developer named Ryan Dahl went onstage to present his project named Node.js. Starting in 2008, Dahl looked at the current web trends and discovered something odd in the way web applications worked. The introduction of the AJAX technology a few years earlier transformed static websites into dynamic web applications, but the fundamental building block of web development didn't follow this trend. The problem was that web technologies didn't support two-way communication between the browser and the server. The test case he used was the Flickr upload file feature, where the browser was unable to know when to update the progress bar as the server could not inform it of how much of the file was uploaded.

Dahl's idea was to build a web platform that would gracefully support the push of data from the server to the browser, but it wasn't that simple. When scaling to common web usage, the platform had to support hundreds (and sometimes...

JavaScript closures

Closures are functions that refer to variables from their parent environment. Using the closure pattern enables variables from the parent() function to remain bound to the closure. Let's take a look at the following example:

function parent() {
    var message = "Hello World";

    function child() {
        alert (message);
    }

    child();
}

parent();

In the preceding example, you can see how the child() function has access to a variable defined in the parent() function. But this is a simple example, so let's see a more interesting one:

function parent() {
   var message = 'Hello World';
    
  function child() {
    alert (message);
   }

   return child;
}

var childFN = parent()
childFN();

This time, the parent() function returned the child() function, and the child() function is called after the parent() function has already been executed. This is counterintuitive to some developers because usually the parent() function's local...

Node modules

JavaScript has turned out to be a powerful language with some unique features that enable efficient yet maintainable programming. Its closure pattern and event-driven behavior have proven to be very helpful in real-life scenarios, but like all programming languages, it isn't perfect, and one of its major design flaws is the sharing of a single global namespace.

To understand the problem, we need to go back to JavaScript's browser origins. In the browser, when you load a script into your web page, the engine will inject its code into an address space that is shared by all the other scripts. This means that when you assign a variable in one script, you can accidently overwrite another variable already defined in a previous script. While this could work with a small code base, it can easily cause conflicts in larger applications, as errors will be difficult to trace. It could have been a major threat for Node.js evolution as a platform, but luckily a solution was found...

Developing Node.js web applications

Node.js is a platform that supports various types of applications, but the most popular kind is the development of web applications. Node's style of coding depends on the community to extend the platform through third-party modules; these modules are then built upon to create new modules, and so on. Companies and single developers around the globe are participating in this process by creating modules that wrap the basic Node APIs and deliver a better starting point for application development.

There are many modules to support web application development but none as popular as the Connect module. The Connect module delivers a set of wrappers around the Node.js low-level APIs to enable the development of rich web application frameworks. To understand what Connect is all about, let's begin with a basic example of a basic Node web server. In your working folder, create a file named server.js, which contains the following code snippet:

var http =...

Summary

In this chapter, you learned how Node.js harnesses JavaScript's event-driven behavior to its benefit. You also learned how Node.js uses the CommonJS module system to extend its core functionality. You learned about the basic principles of Node.js web applications and discovered the Connect web module. You created your first Connect application and learned how to use middleware functions. In the next chapter, we'll tackle the first piece of the MEAN puzzle, when we discuss the Connect-based web framework called Express.

Left arrow icon Right arrow icon
Download code icon Download Code

Description

The MEAN stack is a collection of the most popular modern tools for web development; it comprises MongoDB, Express, AngularJS, and Node.js. Starting with MEAN core frameworks, this project-based guide will explain the key concepts of each framework, how to set them up properly, and how to use popular modules to connect it all together. By following the real-world examples shown in this tutorial, you will scaffold your MEAN application architecture, add an authentication layer, and develop an MVC structure to support your project development. Finally, you will walk through the different tools and frameworks that will help expedite your daily development cycles. Watch how your application development grows by learning from the only guide that is solely orientated towards building a full, end-to-end, real-time application using the MEAN stack!

Who is this book for?

If you are a web or a full-stack JavaScript developer who is interested in learning how to build modern web applications using the MEAN stack, this book is for you.

Product Details

Country selected
Publication date, Length, Edition, Language, ISBN-13
Publication date : Sep 25, 2014
Length: 354 pages
Edition : 1st
Language : English
ISBN-13 : 9781783983292
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

Product Details

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

Packt Subscriptions

See our plans and pricing
Modal Close icon
R$50 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
R$500 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 R$25 each
Feature tick icon Exclusive print discounts
R$800 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 R$25 each
Feature tick icon Exclusive print discounts

Frequently bought together


Stars icon
Total R$ 886.97
Web Development with MongoDB and Node.js
R$272.99
AngularJS Web Application Development Blueprints
R$306.99
MEAN Web Development
R$306.99
Total R$ 886.97 Stars icon

Table of Contents

12 Chapters
1. Introduction to MEAN Chevron down icon Chevron up icon
2. Getting Started with Node.js Chevron down icon Chevron up icon
3. Building an Express Web Application Chevron down icon Chevron up icon
4. Introduction to MongoDB Chevron down icon Chevron up icon
5. Introduction to Mongoose Chevron down icon Chevron up icon
6. Managing User Authentication Using Passport Chevron down icon Chevron up icon
7. Introduction to AngularJS Chevron down icon Chevron up icon
8. Creating a MEAN CRUD Module Chevron down icon Chevron up icon
9. Adding Real-time Functionality Using Socket.io Chevron down icon Chevron up icon
10. Testing MEAN Applications Chevron down icon Chevron up icon
11. Automating and Debugging MEAN Applications 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 Half star icon 4.5
(58 Ratings)
5 star 72.4%
4 star 12.1%
3 star 10.3%
2 star 5.2%
1 star 0%
Filter icon Filter
Top Reviews

Filter reviews by




Marcos Maia Aug 20, 2015
Full star icon Full star icon Full star icon Full star icon Full star icon 5
Totally worth the investment.
Amazon Verified review Amazon
H Feb 10, 2015
Full star icon Full star icon Full star icon Full star icon Full star icon 5
I've really enjoyed this book. It does a good job at overviewing but also giving enough details. My only complaint is that it doesn't talk at all about mean.io or mean.js. But that's not anything wrong with the book, thats just me complaining that there aren't more resources out there describing how to use mean.io/mean.js. This book has been an amazing resource for me.
Amazon Verified review Amazon
DomCat Jan 23, 2016
Full star icon Full star icon Full star icon Full star icon Full star icon 5
Very good and still up to date. Must read for any js developer especially frontend dev. Will back to it as a reference
Amazon Verified review Amazon
T. Powell Dec 12, 2015
Full star icon Full star icon Full star icon Full star icon Full star icon 5
I am a newbie. After reading several books about JavaScript, MongoDB, single-page applications (SPAs), Node.js, the MEAN stack, and a few other books that were detours, this is the one that finally nudged me over the crest of the hill. By the time I finished reading Chapter 9 I could finally say, "Now I get it!"
Amazon Verified review Amazon
xboxremote Aug 11, 2016
Full star icon Full star icon Full star icon Full star icon Full star icon 5
Not quite finished working through this book entirely, but so far it has been amazing. Great example that carries through the whole book, very clear, and easy to understand. I've only caught one (maybe two) errors in the code examples so far (which is pretty good for a book like this). You do need a pretty good understanding of web development, and at least some intro to MVC architecture before you dive into this book. Some of the concepts would be too advanced for a beginner.
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.