What MEAN means?

MEAN stack is a full-stack JavaScript solution that helps you build fast, robust, and maintainable web applications. Combining the powers of MongoDB, Express, AngularJS, and Node.js (hence the acronym), it’s become a popular option for creating dynamic websites and web applications.

  • nodejs a JavaScript run-time built on Google Chrome’s V8 JavaScript engine. It uses an event-driven, non-blocking I/O model that makes it lightweight and efficient.
  • Expressis minimal and lightweight web application server framework for Node inspired by Sinatra, with a myriad of HTTP utility methods and middleware at your disposal, creating a robust API is quick and easy.
  • MongoDBis a free and open-source,cross-platform document-oriented database.
  • AngularJSis a JavaScript framework developed by Google. It provides very comprehensive features like the two-way data binding, routing, DI of services. It’s a complete solution for rapid and awesome front end development.

Shift in the paradigm

“We keep moving forward, opening new doors, and doing new things, because we’re curious and curiosity keeps leading us down new paths.”

-Walt Disney

The transition of a technology from a bunch of curious programmers to an industry standard, isn’t something we witness often. We (.Net developers) have avoided and mocked Open-Source products like Linux, UNIX or anything similar. Anything without a license is not trustworthy and must be avoided at all costs. .Net is better than any other stack; it is not a stack if it is not bundled with Visual Studio and .Net. These views are now transforming, there is a shift in the paradigm.

MongoDB, Express.js, AngularJS, and Node.js are not even a decade old and were already upsetting the order individually and now that they are coupled together, they pose a fierce competition to the existing Stacks.

Why Mean?

Let us consider a trivial example of adding a new field to UI, for instance Client Name:

In ASP.NET MVC you have to make the following changes:

  1. Update the database:
    1. First we have to make ClientName a field nullable.
    2. Then you create a script to populate the appropriate data for the field.
    3. Now you again update ClientName to not null.
  2. Update the Data Model:
    1. Whether you use Entity Framework, Dapper of ADO.Net, you will have to update this once you have made any changes to your database.
  3. Update the View Model:
    1. You are not using MVC if you do not have view models, we need to update this view model too, possibly multiple occurrences to incorporate the changes.
  4. Map the View Model:
    1. The view model is mapped to the data model, if the data model is changed you need to update the mappings as well.
    2. Some third party extensions such as AutoMapper make your life easy, by mapping the fields automatically (If they make sense logically!)
  5. Update the UI:
    1. We need to update the UI to add ClientName.

In Mean Stack this can be achieved in a single step:

<input type="text" ng-model="model.ClientName" required>

This makes MEAN very effective to maintain existing applications.

1. RDMS are overrated:

When working with any RDMS (SQL, MYSQL) at some point in time we have all faced the problem where we forced to club too much data into one column. The major constrain with RDMS is the table structure. For instance the address field, no one shares the exact same format of addresses, some can fit in 2 lines, some require 3 lines; when using RDMS we are forced to fit the address in the 2 columns allocated for it. MongoDB being a NoSQL database provides you the freedom to add/ remove fields based on your requirement without touching the schema of the table.

2. JavaScript for one, JavaScript for all:

MongoDB stores the data in BSON (Binary JSON), NodeJS, AngularJS and Express being JavaScripts work with JSON. MEAN uses the same JSON format for data everywhere, which makes it simpler and efficient. This also makes working with external APIs that much easier: GET, POST, PUT all in the same format.

3. NodeJS is the new Flash:

Node.js was created because concurrency is difficult in many server-side programming languages, and often leads to poor performance. Node.js provides an event-driven architecture and a non-blocking I/O API that optimizes an application’s throughput and scalability. Developers write simple code and Node.js takes over. Node.js uses an event loop, instead of processes or threads, to scale. Callbacks are defined, and the server automatically enters the event loop at the end of the callback definition. Node.js exits the event loop when there are no further callbacks to be performed.

4. Simplicity:

Node.js is incredibly simple. To create a ‘Hello World’ web server in node the following code is sufficient.

// Load the http module to create an http server.
var http = require('http');

// Configure our HTTP server to respond with Hello World to all requests.
var server = http.createServer(function (request, response) {
  response.writeHead(200, {"Content-Type": "text/plain"});
  response.end("Hello World\n");
});

// Listen on port 8000, IP defaults to 127.0.0.1
server.listen(8000);

To do the same in .Net you would require knowledge of IIS, the Machine.config, the Web.config, the Process Model, how Global.asax works, either ASP.NET MVC or WebForms, and how Visual Studio works. Don’t forget to learn how to create a solution, at least one web project, and how to deploy the application to IIS. All of that’s pretty much just as easy and intuitive as Node.js, right?

5. Plug and Play:

Express makes it a breeze to quickly build Web APIs, and its modularity also allows application developers to plug external middleware for additional functionality. There are many middleware available in the community such as HTTP loggers.

MongoDB, Express, AngularJS, and Node.js work really well together, and other options might too. Instead of MongoDB, some apps might only need CouchDB or ReThinkDB. Or perhaps instead of Angular, you favour Ember.js, Backbone.js, or knockout. Or instead of Express you can chose Sails.js, Hapi.js, or Derby.

When to use MEAN STACK

Node.js has a single thread listening for connections. All of the code which you as the Node developer write is executed on this single thread. This single thread is all that is exposed to you. It uses V8 to delegate the I/O work to a thread from an underlying pool of native C++ threads As a result, you would not want to use Node.js when you need to write an application that will do CPU-intensive work such as performing calculations or creating reports

In general, use MEAN when you have highly I/O-bound operations that don’t use much CPU. Do not use MEAN when you need to calculate things which uses a lot of CPU.

What next?

Now that you have a brief idea about MEAN stack, we would be proceeding with the next logical step i.e. installation.

References

https://thinkster.io/mean-stack-tutorial

https://www.codeschool.com/blog/2014/11/18/mean-stack/