This icon indicates a warning or caution.
Tip
This icon indicates a pro tip that will help your development.
Code Samples
This book will mix in concept and code by building applications in each chapter. Each application will be useful in understanding the core concepts and building up to a fully fledged MEAN stack application.
Throughout the chapters, we will work with code samples that build off of each other, leading up to one full application. Well add links to the sample code so that you can download and follow along if you wish. After seeing real examples and concepts in action, youll be able to use these concepts to build your very own projects.
Code License
The sample code in this book is released under the MIT License. Feel free to use any and all parts of them in your own applications and anything you build or write.
Code Repository
The code for the samples in this book can be found at: http://github.com/scotch-io/mean-machine-code.
Well provide links to the specific folders at the start of every application so stay tuned for those.
Get In Contact
If you have any questions, comments, kind words about the book (we love those), or corrections in the book (we like those), feel free to contact us at .
Also, take a look at our site (Scotch.io) for great articles on all sorts of web development topics.
Introduction
Node is an exciting JavaScript language for web development that has been growing in popularity in recent years. It started out for small development projects and has since penetrated the enterprise and can be seen in large companies like Microsoft, eBay, LinkedIn, Yahoo, WalMart, Uber, Oracle, and several more.
Why MEAN?
The MEAN stack uses four pieces of software: MongoDB, ExpressJS, AngularJS, and NodeJS. Using these four tools together lets developers create efficient, well organized, and interactive applications quickly.
Since every component of the stack uses JavaScript, you can glide through your web development code seamlessly. Using all JavaScript lets us do some great things like:
- Use JavaScript on the server-side (Node and Express)
- Use JavaScript on the client-side (Angular)
- Store JSON objects in MongoDB
- Use JSON objects to transfer data easily from database to server to client
A single language across your entire stack increases productivity. Even client side developers that work in Angular can easily understand most of the code on the server side.
Starting with the database, we store information in a JSON like format. We can then write JSON queries on our Node server and send this directly to our front-end using Angular. This is especially useful when you have multiple developers working on a project together. Server-side code becomes more readable to front-end developers and vice versa. This makes everything a little more transparent and has been shown to greatly increase development time. The ease of development will become much more apparent once we start digging into examples and hopefully save you and your team some headaches in the future.
When To Use the MEAN Stack
The MEAN stack benefits greatly from the strengths of Node. Node lets us build real-time open APIs that we can consume and use with our frontend Angular code. Transferring data for applications like chat systems, status updates, or almost any other scenario that requires quick display of real-time data.
- Chat client
- Real-time user updates (like Twitter feed)
- RSS feed
- Online shop
- Polling app
When NOT To Use the MEAN Stack
As with any language or set of languages, there are plenty of scenarios where MEAN wouldnt be the best fit and its very important to recognize this before diving into coding. A lot of the benefits of the MEAN stack and reasons why you would use it are rooted in its use of Node. We see this same trend again with reasons you may not want to use it.
Node is generally not the best pick for CPU intensive tasks. There have been a few arguments for cases where Node actually did well in computationally heavy applications, but for the novice its best to steer away from Node if you know your application requires a lot of computing (in other words lets not try to calculate the 1000th prime number here).
Whos Getting MEAN?
Many developers have shouted their praise for the MEAN stack. This stack uses JavaScript for every operation, which makes it appealing to developers who want to flow smoothly through a project. Some large companies are already reaping the benefits and have integrated Node into many of their operations.
Walmart
Walmart: Walmart began using Node.js in 2012 to provide mobile users with a modern front end experience. Making use of the JavaScript platform, they were able to quickly and easily integrate their existing APIs with their Node application. They also stated that 53% of their Black Friday online traffic went to their Node servers with zero downtime.
Yahoo
Yahoo!: Yahoo started experimenting with Node back in 2010. At first they just used it for small things like file uploads, and now they use Node to handle nearly 2 million requests per minute. They have noted increases in speed and a simpler development process.
Linkedin
LinkedIn LinkedIn began developing the server side of their mobile app entirely with Node. They were previously using Ruby, but since the switch they have seen huge increases in performance, ranging from 2 to 10 times faster.