Friday, March 18, 2016

Understanding the MEAN stack - Part 1 : Node JS

So a couple of weeks I was given this assignment to build a single page web application using the MEAN (MongoDB, Express JS, Angular JS, Node JS) stack as part of an interview. It was a simple todo application with features functionalities to add a todo item, mark a todo item as completed and delete a todo item. Given the fact that I have very little experience with building modern web applications using javascript it was quite a challenging experience. And I guess the whole point of the assignment was to judge how open I am in terms of accepting to work with new technologies and my ability to quickly ramp up on things. Nevertheless I enjoyed working on the application.
I had a little exposure to Node JS and MongoDB during one of my academic projects, but the other two Express JS and Angular JS were very new to me.
So the first order of business was to understand the importance of each of these technologies and how they fit in together for a web application to come to life.
So lets dive into it right away.

Node JS

When you go visit the about page of Node.js the first example they give you is to create a simple HTTP server. I feel this kind of sets an impression on a beginner that Node.js is used for creating a web server. But that is not entirely true. Creating a server is just one of the many capabilities Node.js offers. Node.js is a platform. It is a platform which allows you to use its libraries to build a web server and that is just one application.

So why Node.js?

  • It buys true platform independence. Like Java, Node.js also offers a write once run anywhere kind of environment and this is important not just for your production targets but for your development platforms as well. Linux users and windows users all can publish to a common target without coming across platform specific issues.
  • Its single threaded and event based so it is fast even when handling lots of requests at once.
  • It has a large number of packages accessible through NPM, a package manager. It includes both client and server-side libraries/modules, as well as command-line tools for web development.
Next up Node.js uses what are called as CommonJS modules. Now what are CommonJS modules you ask? It is mainly used to solve the problem of Javascript's single global namespace. Here is an article which talks more about that. So Express JS is actually a module which we will require in for our MEAN stack application. So how do you require in a CommonJS module? We will look at this in the next part where I also speak about our next item in the stack, Express JS.

No comments:

Post a Comment