Before we start on the conceptual part of the NodeJs, I would like to share a short story that many frontend developers might have come across.
Ritesh is a Lead Frontend Developer who got fantastic idea to set up his own startup business. He has the business plan ready with him and now he wants to meet different fund-raisers to get investment in his project so that he could actually start-up.
Before meeting with investors, Ritesh should have working prototype (demo application) to showcase project features and overall look and feel to investors. (Do not forget that Ritesh is a frontend. So, he can do certain things and but not all. Let’s differentiate…)
- Work on branding and design related stuffs like logo, Photoshop (PSD) layouts, etc.
- Even create a data driven prototype using JSON
- Marketing his product/project/service
- Manage teams of developer
- Design a database structure
- Write code to connect a database with his application
- Write code for the server using PHP, Java, Dotnet, Python like server-side languages
Here, “Ritesh Cannot” is one of the reason when NodeJs comes in a picture.
So, What Exactly the NodeJs Is?
To develop a project with NodeJs, having additional framework that can use Node.js methodologies and build over it, is advisable. Express.js and Koa.js are the most popular NodeJs frameworks in this category. I recommend Express.js because it provides easy routing mechanism without much hassle.
My Personal Definition of NodeJs
- Somewhat similar to Google Chrome console
- Another CLI Tool
- Asynchronous, Non-Blocking
- Single Threaded (Event Loop)
- Non Buffering
- Super Fast
Let's say, if we want to write some code for server then first we need to create server and then only we can do the further manipulation. Framework has many things pre-exist which we can use instantly to save extra human efforts in development but that's not the case here with Node. Of course Node APIs are there and the NPM community is vast enough to expand your thoughts.
Somewhat Similar to Google Chrome Console
process are available
document are available in browser console but not in Node console. The same way
process are available in Node console but not in browser console.
console.log is the most common keyword working in both the consoles.
Another CLI Tool
Using Node is required to be more familiar with Command Line Interface (CLI). It might be inconvenient for developers who are not used to with command line. But once you get familiar with commands, I am sure it will be more fun and faster than your usual development flow.
However, there are many addons/plugins available which you can install into your IDE. I have used Bracket's Node.js plugin and it was great experience.
Asynchronous, Non-Blocking, Single Threaded and Event Loop
These all are technical terms and mostly concern with the performance.
Asynchronous is an execution approach which doesn't wait to be finished and move to the other execution. So if we see traditional synchronous execution, it waits for any request to be completed and then only move to the next execution in the queue. So asynchronous is more faster.
Asynchronous uses similar approach that we have in HTML5 Web Workers for scripts.
Non-blocking means as and when executions happen, it will return immediately with whatever result it has without putting your thread to sleep (with high probability).
Event Loop is another approach which always waits for something to happen. Here "something" is an event. If event occurred, then we can define the next step with a callback function. Callback function is important because it give instruction for the next execution. If we don't have callback function then it will continue iterating the same event loop infinitely. However, we can minimize the iterations using
A Buffer is a chunk of memory, just like you would have it in C/C++. You can interpret this memory as an array of integer or floating point numbers of various lengths, or as a binary string. Unlike higher-level data structures like arrays, a buffer is not resizable.
This post is more towards the theoretical concepts of the NodeJs. I am sorry if you feel bored about it. But yes, this would surely help to start with NodeJs. Working on Node projects is going to be fun.
My next post will be on - Getting Started with NodeJs.
Some Negative Factors of NodeJs
If you are going to consider NodeJs for your next project then you should be clear on the negative side of the NodeJs. Below is an interesting thread on Quora, you must read, before making any decision on the Node.
If you have more to speak up then don't hesitate to use comment section below.
Happy Learning :).
- How To Node
- NodeJs - Dotnet Tricks
- Node School
- Understand Callback Function
- Problems with NodeJs Event Loop
Also published on Medium.