When learning new technologies or even improving our existing skill set, we are always interested in full-fledged applications: how the application is built from the concept phase to an actual running application, what pain points can different technologies solve, and what guidelines we need to follow to ease our development cycle.
Speaking of technologies, probably the most widespread of them all is JavaScript. I think the good and bad part of JavaScript is its popularity. For decades, we have had no technology that is so widely spread and ready to be integrated on different platforms.
Besides running JavaScript in the browser, which we are all so used to, for a few years we can easily run our JS code on the server using Node.js. It does not stop here, as we can start developing powerful IoT projects using only JavaScript.
For many years, we saw a movement of having a single technology that dominates every platform. I think the JavaScript stack, yes stack, at the moment is big game changer. Probably, you are thinking now that it's not that perfect or colorful; yes, I cannot agree more with you, but the evolution is so rapid—and new things are pushed every day, every minute—that we are on the edge of a technological revolution.
Wait! What? Yes, we can be a part of the revolution, we can be trend setters, we can shape the future of the Web, mobile, and IoT (maybe the universe? But of course). We can push the limits and prove that we can do great things, and we can progressively improve ourselves and the people around us.
The idea behind writing this book was to provide a guide and a higher perspective of applications built using the MEAN stack. As I interact with lots of people at the company Evozon, where I'm working, I see a big desire in people to touch and feel how applications are built using different technology stacks.
Especially in popular technologies such as JavaScript, Node.js, and MongoDB. But usually, finding full end-to-end example applications is hard. Don't get me wrong; the Internet is full of great stuff, brilliant people, and so many mind-blowing things, but it is also full of noise and uncertainty, and it's hard to know which path is right or wrong and what should be done in certain scenarios.
That's why we want to showcase different scenarios of building applications using the MEAN stack. Probably it's not the only way of doing things, but it should provide you with a starting point, or give you an insight into how certain parts of an app are built.
This is not a getting started book on Node.js and Angular 2. It will jump right into action and showcase six built-from-the-beginning applications, each with different use cases and solving a high-level problem.
Writing a book takes time, a lot of energy, and a little bit of fear. I've feared that I'll never finish this book. It was a long run, and the funniest part was that the first three chapters were written in an earlier version of AngularJS. Don't worry! Everything is shipped using Angular 2.
As you might have guessed, we had a long run and rewrote everything using the currently-in-beta-release Angular 2. Why? Because, as I told you before, we want to push our limits. We want to grow and master new ways of building modern applications.
I've tried to cover a variety of applications built using the MEAN stack, ranging from a simple contact manager and a real-time chat application to a full auction website.
Chapter 1, Contact Manager, will cover the process of building an introductory application to save your contacts in MondoDB. The chapter will introduce you to TDD (short for Test-Driven Development) for your Node.js application. You will learn how to build an Angular 2 app that will access data from the Express API.
Chapter 2, Expense Tracker, is going to dive deep into working with monetary data in JavaScript and storing this data in MongoDB using the exact precision approach. Also, you are going to learn how to add a token for authentication of each request in the client application by extending the built-in HTTP service in Angular. Besides this, you'll see how to use the aggregation framework from MongoDB and display the result in your Angular application.
Chapter 3, Job Board, will focus on building a more consumer-level application that will enable users to define a custom profile with dynamic data. You will use reactive extensions in Angular to create different communication layers in your application. On the backend, we are going to build a RESTful API using Node.js and set up a boilerplate application from the previously built apps that we are going to use further in the book.
Chapter 4, Chat Application, will start reusing the boilerplate built in the previous chapter. But the most fun part will begin when we create a chat service layer that uses SocketIO. This will enable both the backend and the frontend Angular app to communicate in real time to send messages. The chat service will be built in such a way that it's easily extendable with new modules, besides instant messaging, such as when a user is online or goes offline.
Chapter 5, E-Commerce Application, is going to reflect the ease of storing unstructured data in MongoDB. We'll discuss in detail how to store your product catalog in a NoSQL database. Besides this, our initial architecture from the previous chapters is going to get a new form, and we'll experiment with micro-apps, each with its own responsibility. The micro-apps will use the core e-commerce module that encapsulates all the business logic. Also, this chapter will cover two client apps, one built with a totally different technology, and an admin application using Angular 2.
Chapter 6, Auction Application, is going to be more of an extension of the previous chapter; in other words, it will use the e-commerce API to fetch product information and authenticate users. This will push us not only to reuse existing code but rely on other services for faster prototyping when building products. Also, we are going to dive deeper into RxJs and see how we can build a real-time bidding system in our Angular auction application using SocketIO on the server side.
You will require any modern web browser (such as Chrome's latest version or IE 10+), the Node.js platform installed on your machine, and version 3.2 or higher of MongoDB. Optionally, you can install any web server, such as Nginx, Apache, IIS, or lighttpd, to proxy requests to your Node.js application.
If you are a web developer with a basic understanding of the MEAN stack, experience of developing applications with JavaScript, and basic experience with NoSQL databases, then this book is for you.
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: "Create a file called app/models/token.js
."
A block of code is set as follows:
'use strict'; const LEN = 256; const SALT_LEN = 64; const ITERATIONS = 10000; const DIGEST = 'sha256'; const crypto = require('crypto'); module.exports.hash = hashPassword; module.exports.verify = verify;
When we wish to draw your attention to a particular part of a code block, the relevant lines or items are set in bold:
require('./config/express').init(app);
require('./config/routes').init(app);
Any command-line input or output is written as follows:
Authentication Basic authentication √ should authenticate a user and return a new token √ should not authenticate a user with invalid credentials 2 passing
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: "It triggers an event when the Save button is clicked on and the form is submitted."
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 <[email protected]>
, 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 www.packtpub.com/authors.
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.
You can download the example code files for this book from your account at http://www.packtpub.com. If you purchased this book elsewhere, you can visit http://www.packtpub.com/support and register to have the files e-mailed directly to you.
You can download the code files by following these steps:
Log in or register to our website using your e-mail address and password.
Hover the mouse pointer on the SUPPORT tab at the top.
Click on Code Downloads & Errata.
Enter the name of the book in the Search box.
Select the book for which you're looking to download the code files.
Choose from the drop-down menu where you purchased this book from.
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 https://github.com/PacktPublishing/MEAN-Blueprints. We also have other code bundles from our rich catalog of books and videos available at https://github.com/PacktPublishing/. 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 http://www.packtpub.com/submit-errata, 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 https://www.packtpub.com/books/content/support 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 <[email protected]>
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 <[email protected]>
, and we will do our best to address the problem.