Book Image

MEAN Web Development - Second Edition

By : Amos Q. Haviv
Book Image

MEAN Web Development - Second Edition

By: Amos Q. Haviv

Overview of this book

The MEAN stack is a collection of the most popular modern tools for web development that helps you build fast, robust, and maintainable web applications. Starting with the MEAN core frameworks, this pragmatic 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. You will learn the best practices of maintaining clear and simple code and will see how to avoid common pitfalls. 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!
Table of Contents (18 chapters)
MEAN Web Development Second Edition
About the Author
About the Reviewer


Back in the spring of 1995, web browsers were very different from present day browsers. It had been 4 years since the release of the WorldWideWeb (the first Internet browser written by Tim Berners-Lee, later renamed Nexus), 2 years since the initial release of Mosaic, and Internet Explorer 1.0 was a few months away from release. The World Wide Web began to show signs of popularity, and though some of the big companies showed interest in the field, the main disruptor back then was a small company named Netscape.

Netscape's already popular browser, Netscape Navigator, was in the works for its second version, when the client engineering team and co-founder Marc Anderseen decided that Navigator 2.0 should embed a programming language. The task was assigned to a software engineer named Branden Eich, who completed it in ten days between May 6 and May 15, 1995, naming the language Mocha, then LiveScript, and eventually JavaScript.

Netscape Navigator 2.0 was released in September 1995 and transformed the way we perceived the web browser. By August 1996, Internet Explorer 3.0 introduced its own implementation of JavaScript, and in November of that year, Netscape had announced that they had submitted JavaScript to ECMA for standardization. In June 1997, the ECMA-262 specification was published, making JavaScript the de facto standard programming language for the Web.

For years, JavaScript was denigrated by many as the programming language for amateurs. JavaScript's architecture, fragmented implementation, and original "amateur" audience made professional programmers dismiss it. But then AJAX was introduced, and when Google released their Gmail and Google Maps applications in the mid-2000s, it suddenly became clear that AJAX technology could transform websites into web applications. This inspired the new generation of web developers to take JavaScript development to the next level.

What began with the first generation of utility libraries, such as jQuery and Prototype, soon got boosted by Google's next great contribution, the Chrome browser and its V8 JavaScript engine, released at the end of 2008. The V8 engine, with its JIT compiling capabilities, greatly enhanced JavaScript performance. This led to a new era in JavaScript development. 2009 was JavaScript's annus mirabilis; suddenly, platforms such as Node.js enabled developers to run JavaScript on the server, databases such as MongoDB popularized and simplified the use of JSON storage, and frameworks such as Angular and React are simplifying the creation of complex frontend applications. More than 20 years after its original debut, JavaScript is now everywhere. What used to be an "amateur" programming language, capable of executing small scripts, is now one of the most popular programming languages in the world. The rise of open source collaboration tools, along with the devoted involvement of talented engineers, created one of the richest communities in the world, and the seeds planted by many contributors are now flourishing in a burst of sheer creativity.

The practical implications are enormous. What was once a fragmented team of developers, each an expert in their own domain, can now become a homogeneous team capable of developing leaner, more agile software together using a single language across all layers.

There are many full-stack JavaScript frameworks out there, some built by great teams, some that address important issues, but none of them are as open and modular as the MEAN stack. The idea is simple, we'll take MongoDB as the database, Express as the web framework, Angular as the frontend framework, and Node.js as the platform, and combine them in a modular approach that will ensure the flexibility needed in modern software development. MEAN's approach relies on the communities around each of the open source modules keeping it updated and stable, ensuring that if one of the modules becomes useless, we can just seamlessly replace it with a better-suited one.

I would like to welcome you to the JavaScript revolution and assure you I will do my best to help you become a full-stack JavaScript developer.

In this book, we'll help you set up your environment and explain how to connect the different MEAN components together using the best modules. You'll be introduced to the best practices of maintaining your code clear and simple and be shown how to avoid common pitfalls. We'll walk through building your authentication layer and adding your first entity. You'll learn how to leverage JavaScript non-blocking architecture in building real-time communication between your server and client applications. Finally, we'll show you how to cover your code with the proper tests, and we'll show you what tools to use to automate your development process.

What this book covers

Chapter 1, Introduction to MEAN, introduces you to the MEAN stack and shows you how to install the different prerequisites on each OS.

Chapter 2, Getting Started with Node.js, explains explain the basics of Node.js and how it is used in web application development.

Chapter 3, Building an Express Web Application, explains how to create and structure an Express application by implementing the MVC pattern.

Chapter 4, Introduction to MongoDB, explains the basics of MongoDB and how it can be used to store your applications' data.

Chapter 5, Introduction to Mongoose, shows how to use a Mongoose to connect an Express application with a MongoDB database.

Chapter 6, Managing User Authentication Using Passport, explains how to manage your users' authentication and offer them diverse login options.

Chapter 7, Introduction to Angular, explains how to implement an Angular application in conjunction with your Express application.

Chapter 8, Creating a MEAN CRUD Module, explains how to write and use your MEAN application's entities.

Chapter 9, Adding Real-time Functionality Using, shows you how to create and use real-time communication between your client and server.

Chapter 10, Testing MEAN Applications, explains how to automatically test the different parts of your MEAN application.

Chapter 11, Automating and Debugging MEAN Applications, explains how to develop your MEAN application more efficiently.

What you need for this book

This book is suitable for beginner and intermediate web developers with basic knowledge of HTML, CSS, and modern JavaScript development.

Who this book is for

This book is aimed at web developers interested in learning how to build modern web applications using MongoDB, Express, Angular, and Node.js.


In this book, you will find a number of text styles that distinguish between different kinds of information. Here are some examples of these styles and an explanation of their meaning.

Code words in text, database table names, folder names, filenames, file extensions, pathnames, dummy URLs, user input, and Twitter handles are shown as follows: "To test your static middleware, add an image named logo.png to the public/img folder."

A block of code is set as follows:

const message = 'Hello World';

exports.sayHello = function() {

When we wish to draw your attention to a particular part of a code block, the relevant lines or items are set in bold:

const express = require('express');
const app = express();


console.log('Server running at http://localhost:3000/');

Any command-line input or output is written as follows:

$ npm start

New terms and important words are shown in bold. Words that you see on the screen, for example, in menus or dialog boxes, appear in the text like this: "Once you click on the Next button, the installation should begin."


Warnings or important notes appear in a box like this.


Tips and tricks appear like this.

Reader feedback

Feedback from our readers is always welcome. Let us know what you think about this book—what you liked or disliked. Reader feedback is important for us as it helps us develop titles that you will really get the most out of.

To send us general feedback, simply e-mail , and mention the book's title in the subject of your message.

If there is a topic that you have expertise in and you are interested in either writing or contributing to a book, see our author guide at

Customer support

Now that you are the proud owner of a Packt book, we have a number of things to help you to get the most from your purchase.

Downloading the example code

You can download the example code files for this book from your account at If you purchased this book elsewhere, you can visit and register to have the files e-mailed directly to you.

You can download the code files by following these steps:

  1. Log in or register to our website using your e-mail address and password.

  2. Hover the mouse pointer on the SUPPORT tab at the top.

  3. Click on Code Downloads & Errata.

  4. Enter the name of the book in the Search box.

  5. Select the book for which you're looking to download the code files.

  6. Choose from the drop-down menu where you purchased this book from.

  7. Click on Code Download.

Once the file is downloaded, please make sure that you unzip or extract the folder using the latest version of:

  • WinRAR / 7-Zip for Windows

  • Zipeg / iZip / UnRarX for Mac

  • 7-Zip / PeaZip for Linux

The code bundle for the book is also hosted on GitHub at We also have other code bundles from our rich catalog of books and videos available at Check them out!


Although we have taken every care to ensure the accuracy of our content, mistakes do happen. If you find a mistake in one of our books—maybe a mistake in the text or the code—we would be grateful if you could report this to us. By doing so, you can save other readers from frustration and help us improve subsequent versions of this book. If you find any errata, please report them by visiting, selecting your book, clicking on the Errata Submission Form link, and entering the details of your errata. Once your errata are verified, your submission will be accepted and the errata will be uploaded to our website or added to any list of existing errata under the Errata section of that title.

To view the previously submitted errata, go to and enter the name of the book in the search field. The required information will appear under the Errata section.


Piracy of copyrighted material on the Internet is an ongoing problem across all media. At Packt, we take the protection of our copyright and licenses very seriously. If you come across any illegal copies of our works in any form on the Internet, please provide us with the location address or website name immediately so that we can pursue a remedy.

Please contact us at with a link to the suspected pirated material.

We appreciate your help in protecting our authors and our ability to bring you valuable content.


If you have a problem with any aspect of this book, you can contact us at , and we will do our best to address the problem.