Go to ...

Onlive Infotech

Onlive Infotech on Google+RSS Feed

Tuesday, February 28, 2017

Web Development Basics: What Is Node.js?

Node.jsUnless you’ve been living with your head under a rock for the past couple of years, you’ll have heard about Node.js — it’s the hottest thing to happen in the JavaScript world for quite some time. But, if you’re a traditional JavaScript developer or a hobbyist web developer, it might not be clear to you exactly why Node.js is worth getting excited about.

In this article, I’d like to have a look at what Node.js is for, its major benefits, and why you might want to think about adding yet another tool to your web development kit.

What Is Node.js?

In a nutshell, Node.js is a server-side JavaScript implementation. Until recently, JavaScript ran mostly in the browser and even there it ran slowly. It wasn’t suitable for server-side development — devs would use JavaScript for the front-end and turn to a language like Python or PHP for back-end development.

When Google released its V8 JavaScript interpreter, the landscape changed. With V8, JavaScript execution was a lot faster; fast enough to compete with languages like PHP. Node.js leverages V8, along with some other clever components, to provide a complete JavaScript environment for building network applications like web servers and web apps.

This is great for front-end developers, because they could now apply all of their JavaScript knowledge to back-end development.

What Makes Node Different?

The Node.js site describes it like this:

“Node.js® is a platform built on Chrome’s JavaScript runtime for easily building fast, scalable network applications. Node.js uses an event-driven, non-blocking I/O model that makes it lightweight and efficient, perfect for data-intensive real-time applications that run across distributed devices.”

I’ve already explained about the runtime and the sort of applications you can build with Node.js, but the crucial part of this description is the bit about the “event-driven non-blocking I/O model”. Node.js is fast and resource efficient because it is event-driven, and doesn’t use a more traditional thread-based system. What that means can be quite difficult to understand, and to explain it I’m going to borrow an analogy from developer Dan York.

Think about a doctor’s reception. There is one receptionist and a long queue of patients. Each patient has to fill in several forms before they can be seen by the doctor. There are two ways of handling this situation. The receptionist can give each patient the forms and wait until they are completed before dealing with the next patient. This is analogous to a thread-driven system. The receptionist is blocked while the forms are filled in. The only way to scale this system is to add more receptionists (threads). The Apache web server works like this, which is why it’s quite inefficient, especially under heavy load. It essentially duplicates itself for each request, taking up a lot of resources. Thread-based systems are also difficult to think about and code.

The second way of handing the queue at the reception would be to give each patient their forms, and then send them away while they are competed. When the forms are filled, the patient rejoins the queue. This way, the receptionist can immediately deal with the next patient — he isn’t blocked by the form-filling patient. The system is event-driven — the receptionist deals with events — patients requesting forms, patients returning filled-in forms — rather than being blocked or needing a new receptionist for each patient.

Node.js is event-driven, which makes it perfect for building network applications. I/O requests are not blocking, which means that Node.js doesn’t sit idle while waiting for I/O and it doesn’t have to spawn multiple threads to deal with multiple requests.

In summary, Node.js is a fast, event-based JavaScript environment for building network applications (and other things) and it allows front-end developers to transfer their skills to the back-end.

If this has whetted your appetite for Node.js, check out these resources to learn more.

for more detail. Email Marketing

Tags: , , , , , ,

More Stories From Web Hosting

About Onlive Infotech,