DEV Community

Cover image for It's All About NodeJS
🆖 Karan Oza
🆖 Karan Oza

Posted on

It's All About NodeJS

"One of the main reasons why NodeJS is popular is because it uses the JavaScript as their main application to create new application. Plus, JavaScript is the developers first choice to develop new web applications. The new and robust framework is introduced to many new developers to create the wow factor. Want to know What's that WOW factor is then this article is for you…"

NodeJS

History of NodeJS

Download nodejs

What Exactly is NodeJS?

what is nodejs?

NodeJS = Runtime Environment + JavaScript Library

  • Node.js is an open-source server side runtime environment built on Chrome's V8 JavaScript engine. It provides an event driven, non-blocking (asynchronous) I/O and cross-platform runtime environment for building highly scalable server-side application using JavaScript.

  • Node.js is open source, completely free, and used by thousands of developers around the world.

  • For NodeJS, you should have a basic understanding of JavaScript. As you going to develop web-based applications using Node.js, it will be good if you have some understanding of other web technologies such as HTML, CSS & basic JavaSscript.

"It simply means that you can use JavaScript for Backend development".

Why NodeJS?

Alt Text

Lets deep dive into some awesome feature of NodeJS :

1. NON-BLOCKING :

Non blocking means that while we are waiting for a response for something outside of our execution chain e.g. loading some data, reading from a database or polling a remote service, we continue executing the next tasks in the stack. This concept is revolutionary and make NodeJS extremely fast and efficient.

2. SINGLE THREADED

NodeJS is a single threaded language which in background uses multiple threads to execute asynchronous code. It is non-blocking which means that all functions or callbacks are delegated to the event loop and they are ( or can be ) executed by different threads. That is handled by NodeJS run-time.

3. ASYNCHRONOUS AND EVENT DRIVEN

All APIs of Node.js library are asynchronous, that is, non-blocking. It essentially means a Node.js based server never waits for an API to return data. The server moves to the next API after calling it and a notification mechanism of Events of Node.js helps the server to get a response from the previous API call.

What is the difference between Synchronous and Asynchronous?

Synchronous : Execute something synchronously, you wait for it to finish before moving on to another task.

Asynchronous: Ask for something to happen, get notified when it does. Do other stuff in the meantime.

Async NOdejs

The server can respond to multiple requests at a time. It won't stop or block any API request and will respond to all when the response is ready to send accordingly.

Every thing is event based. Such kind of approach will fire callback (functions most of the time) as the event occur (state changes). An event based system is always be in circular loop to execute it's responsibilities

4. Node Package Manager - NPM

  • npm is the world's largest Software Registry.

  • The registry contains over 700,000 code packages.

  • Open-source developers use npm to share software.

  • Many organizations also use npm to manage private development.

  • npm is free to use.

module counts

You can download all npm public software packages without any registration or login.

C:\>npm install <package>
Enter fullscreen mode Exit fullscreen mode
  • All npm packages are defined in files called package.json.

package.json

5. No Buffering

Node.js applications never buffer any data. These applications simply output the data in chunks. so user can easily view the videos or stream without interruption.

streaming

6. Easily Scalabale and Light weight :

Since it's a lightweight technology tool, using Node.js for microservices architecture is a great choice.
Accordingly, breaking the application logic into smaller modules, micro-services, instead of creating a single, large monolithic core, you enable better flexibility and lay the groundwork for further growth. As a result, it is much easier to add more micro-services on top of the existing ones than to integrate additional features with the basic app functionality.

Where we can use NodeJS?

According to the latest survey made by NodeJS, web applications are the top use case with the share of 85%. Taking into account all the strengths and weaknesses of this JS run-time environment, we composed a list of the hands-on solutions where you can leverage the technology.

web dev

1. Single Page Applications

A single-page app (SPA) involves the allocation of an entire application on one page. In that case, Node.js app development is a good fit for making SPAs due to its asynchronous data flow on the backend. The event loop "catches" simultaneous client's requests which provides a smooth data update. In practice, it eliminates the necessity of refreshing the page every time to get new data.

2. Streaming Applications

Streams are one of the fundamental concepts that power Node.js applications.

stream

  • Every day we use streaming services for listening to music or watching videos. Without downloading the content, we can bring your favourite TV series just on the internet.

  • So is Nodejs a good choice to stream data? Of course! It has built-in streams module allowing you to transmit a huge amount of data in chunks, sequentially. Thanks to this, you don't have to temporarily store or cache data in your application memory at all. Also, you can work on chunks while streaming, so e.g. encoding a video won't be a problem anymore.

3. Chat Application

chat app

  • Node.js provides all basic functionalities for building real-time chats of any complexity. In particular, Node has a powerful Event API that facilitates creating certain kinds of objects ("emitters") that periodically emit named events "listened" by event handlers. 

  • Thanks to this functionality, Node.js makes it easy to implement server-side events and push notifications widely used in instant messaging and other real-time applications.

4. REST APIs

Application programming interfaces (APIs) based on representational state transfer (REST) hold a fundamental position in building modern enterprise software architectures.

A REST Server simply provides access to resources and REST client accesses and modifies the resources using HTTP protocol. Here each resource is identified by URIs/ global IDs. REST uses various representation to represent a resource like text, JSON, XML but JSON is the most popular one.

Node.js offers Express.js framework to build the lightweight and fast REST APIs.

5. Real Time Applications

Real-time collaboration applications offer a wide variety of software solutions for co-browsing, project management, video and audio conferencing.

socket.io

Node.js is very good at handling lots of I/O operations, you can use it to build a real-time application, for example, a chat room where people can talk to each other in real-time. Or maybe a collaboration tool, where co-workers will work on the same document at the same time. Building a video conference app also won't be a problem. It is possible thanks to Node's Events API and WebSockets.

As in the case of the real-time chats, Node's asynchronous and event-based architecture is a great fit for collaboration apps. In these applications, many events and I/O requests occur concurrently. For example, several users can edit the same paragraph, comment, post messages, and attach media. Changes to one piece of content might be applied only after a cascade of events, where each step depends on the previous one.

6. Application Monitoring

Another common use-case in which web-sockets fits perfectly: we can track website visitors and visualizing their interactions in real-time. You could be gathering real-time stats from your user, or even moving it to the next level by introducing targeted interactions with your visitors by opening a communication channel when they reach a specific point in your site

Imagine how you could improve your business if you knew what your visitors were doing in real-time - if you could visualize their interactions. With the real-time, two-way sockets of Node.js, now you can.

Stacks Of NodeJS

stacks

MERN Stack : MongoDB + ExpressJS + React+ NodeJS

MEAN Stack : MongoDB + ExpressJS + Angular + NodeJS

MEVN Stack : MongoDB + ExpressJS + VueJS+ NodeJS

Who Use NodeJS?

Node.js is increasingly becoming a go-to technology for multiple companies across the globe. As Node.js emphasizes on concurrency, speed, and intensive data exchange along with employing push technology over web sockets, it has helped companies to build various applications such as social media apps, video and text chat engines, real-time tracking apps, online games and collaboration tools. Here are global giants who trusts NodeJs :

companies

10 Global Companies that rely on NodeJS

  1. NASA
  2. Netflix
  3. PayPal
  4. Uber
  5. Linkedin
  6. Medium
  7. Trello
  8. eBay
  9. Groupon 
  10. Walmart

Resources To learn

Tutorials

Videos

Courses

nodejs impact on career

Conclusion :

"This is simple, Node.js is a clear market winner. So, Now you know how NodeJS rule the Web Development world, why it is so popular and where it can be implemented. You can decide whether Node.js is a good fit for you, and launch your first web app with NodeJS."

References : nodejs.org, software house, netguru

"If you wanna CODE then start learn NODE…!"

Connect me on Twitter and LinkedIN

If you want me to make an article on any concept then leave the topic down in the comments.

Feedback are most welcome

Top comments (20)

Collapse
 
wulymammoth profile image
David

I'm not a fan of NodeJS at all, but it is a gateway to backend web for folks that are JS-inclined. Are you familiar with Ryan Dahl's latest project? Deno? He seeks to right all the wrongs in NodeJS.

Most of the former Joyent team is now Oxide Computing working heavily in Rust and firmware.

I'm sharing this just so people realize that while NodeJS currently has mind-share and popularity, it's momentum has certainly slowed and it is a platform with a lot of challenges that other language platforms don't have.

Collapse
 
ozakaran profile image
🆖 Karan Oza

Yess David, Deno uses ES Modules as the default module system, whereas Node. js uses CommonJS.

And it's totally depends on Developers choice most of stacks are preferred Javascript as there first language so may be they either choose NodeJS or The one who comfortable with TypeScript go with the Deno as you mentioned...

Btw thanks for take your time and sharing this🤗🙏

Collapse
 
brianmcbride profile image
Brian McBride

I'm not sure I agree that NodeJS has lost momentum.
I would never use it as a tool for firmware. Rust is an alternative for C/C++.

When it comes to serverless, NodeJS is being picked up more and more from what I see. There are a lot of Java and .NET developers who are now leveraging Typescript + NodeJS for their back end services. There is just a lot less boilerplate and faster development time in many cases.

I would also be interested in "a lot of challenges that other language platforms don't have". Every platform has its challenges. Typically developers find the language they are used to less problematic than the one they don't use every day. I bad-mouthed Java when I was working in Objective-C. I talked bad about C# when I was working in Java. I swore that Node would never be a viable base for servers in production - and yet now most of my serverside code is Typescirpt + NodeJS.

Collapse
 
wulymammoth profile image
David

We can agree to disagree, but can we agree that Deno has a high likelihood of chipping away at Node looking forward?

Yes, Rust is an alternative to C and C++. It's staking a claim in the performance game. Deno is written in Rust. Rust is also getting some love at big companies including both Microsoft (GitHub as well) and Google. It is also being used at Discord.

I would also be interested in "a lot of challenges that other language platforms don't have". Every platform has its challenges.

Sure. Let me expound -- this is anecdotal and I've worked in Ruby, Node, Python, Golang, Elixir, and now Rust in production environments. I'm also speaking exclusively for backend web services, where most of my experience is. Of these, I default to Elixir (Erlang VM/BEAM). Operationally, probably the best platform to use for long-running services. Why? It comes out of the box with runtime introspection (observer) allowing an operator to go in and look at issues happening in real time, fault-tolerance built in (supervision trees) that provides "self-healing" that's great for avoiding some pages during the middle of the night, clustering and service discovery out of the box (granted that you're running on a cloud provider that supports it or VPC, but not Heroku). So while, every platform, including the BEAM has its challenges, it's less painful than that of Node. More often than not, because most of us know JS, we default to "easy to write" implicitly. Remember, though, that code is read more times than it is written, and maintenance has a cost. Node/JavaScript when compared to even the other language that I mention has many challenges that for me, and I'd imagine for others (if they're familiar with other platforms) would choose not to adopt. Node/JS isn't very good for numbers or mathematics. The package management is pretty gnarly (i.e. peek at node_modules lately?). You have to adopt the async model of programming -- which is much harder to debug and introspect -- compare this to Elixir where one can stick an IO.inspect into the middle of a pipeline/chain of function calls.

I don't make as bold claims and/or predictions as you do. Sometimes you're right and sometimes you're wrong. I'm simply citing an observation that is perhaps unique to the bubble/pocket of tech that I'm in (San Francisco). Maybe you've grown to love Node and TS and that's fine, because you and the others that are enjoying it will be its torch-bearers. And most of us will default to starting any project in something we're most familiar with or make choices from things we're familiar with. I'm not going to tell someone to go do Elixir or Rust while building a start-up or new project if they don't already know it. That would be signing up for zero productivity. For me, having worked in the platforms above, I would never choose Node. I still enjoy writing JavaScript and would leave it to just client-side/browser-specific applications. Would I mind reading someone's small project in it? No. However, I would take pause before I signed up to work in Node in production and most certainly wouldn't start a project in it. I would certainly explore Deno before Node if JS/TS is the language choice. I find Node/JS to have the most "footguns" of all the languages/platforms that I've listed.

I wrote my post simply to urge people to try new things -- explore. It opens one's world to the possibilities and what's been done about the parts you don't like in your language and platform. That's the message I would hope people are taking from it :)

Thread Thread
 
brianmcbride profile image
Brian McBride

Thanks for the excellent reply.

I wouldn't say I "love" Node/TS. I firmly believe pick the right tool for the right job. What I am saying is that if you want to build out a GraphQL server or even some serverless RESTful API endpoints - the Node/TS stack is currently my goto.

But, I will agree that that stack needs better debugging/testing/introspection tools. Some of the cloud vendors offer some drop-in libs. Async, threads, or any non-blocking style coding is going to be harder to debug for sure. My teams use strong linting rules and code formatters so that there is some guidance on how to structure code.

Anyway. I do appreciate your thoughts and I very much agree that people should explore :)

Thread Thread
 
wulymammoth profile image
David • Edited

Yeah -- definitely. However, for some of us, we only have a single tool. Anything and everything that can be done in JavaScript, will be done in JavaScript. It's a double-edged sword -- it does open up the doors to areas that formerly weren't open before (e.g., hardware/IoT, ML, etc), because it is a pretty large undertaking to learn new languages and their ecosystems. JS certainly has served as the "gateway language" for many, including myself. It's hard to see how different things could be until we've actually experienced them. When I only did JavaScript, it was easy to just acknowledge the warts and work around them as a fact of life. You're also right about some of the drop-ins some providers have come up with to better the experience.

And no problem -- I thoroughly enjoy discussions around different technologies and reconfiguring my line of thought with the advent of new info and data points :)

Out of curiosity, though, being that you've worked in Java, do you like Java? If not, what about other JVM languages? I've never worked in Java in production, but have fiddled around with a few JVM langs.

Collapse
 
__akash__19 profile image
Akash bhandwalkar

Wonderful article Karan 👍

Collapse
 
ozakaran profile image
🆖 Karan Oza

Thank you so much Akash🤗🙏

Collapse
 
bykof profile image
Michael Bykovski

What is this website where you write about asynchronous and event driven?
With the callback queue and event loop

Collapse
 
ozakaran profile image
🆖 Karan Oza

It's from Andrew Mead's course that I did. He explained it really well with this pattern

Collapse
 
perpetual_education profile image
perpetual . education

We needed this in 2010! Thanks for the great article.

Collapse
 
ozakaran profile image
🆖 Karan Oza

Thanks for the feedback 🤗🙏

Collapse
 
pankajtanwarbanna profile image
Pankaj Tanwar

Keep writing <3

Collapse
 
ozakaran profile image
🆖 Karan Oza

Yup!! I will...

Collapse
 
anzhari profile image
Anzhari Purnomo

Wow, this is really comprehensive! Consider this a free NodeJS intro bootcamp.

Collapse
 
ozakaran profile image
🆖 Karan Oza

Glad you find it helpful!! Thanks for the feedback!!!

Collapse
 
delta456 profile image
Swastik Baranwal

Well explained

Collapse
 
ozakaran profile image
🆖 Karan Oza

Thanks for the feedback 🤗🙏

Collapse
 
petroskoulianos profile image
Petros Koulianos

Great article !!!!!

Collapse
 
ozakaran profile image
🆖 Karan Oza

Thank you so much 🤗🙏