What is Node.js and why was it created?

I decided to start a series of posts covering all the fundamentals of Node.js. In the future, I plan to do the same with PHP and perhaps Laravel. Since I often revisit the fundamentals to keep them fresh in my mind, I thought it would be helpful not only for you but also for me to have a reference. If I miss anything, I’ll add it in new posts over time. 😉

So… Let’s start from Node.js:

Node.js is an open-source runtime environment that allows developers to run JavaScript on the server side. Think of it as giving JavaScript superpowers beyond the browser. Created by Ryan Dahl in 2009, Node.js was designed to make building scalable network applications easier and more efficient. 🚀

Why was it created? 🤔❔

Before Node.js, JavaScript was primarily used for client-side scripting. Developers faced challenges with handling multiple concurrent connections and scaling applications. Traditional server-side technologies like Apache created a new thread for each request, leading to high memory consumption and inefficiency under heavy load.

Ryan Dahl saw this problem and created Node.js to handle multiple connections simultaneously, using an event-driven, non-blocking I/O model. This allows Node.js to manage thousands of connections efficiently without consuming large amounts of memory, much like a skilled juggler keeping multiple balls in the air effortlessly. 🤹‍♂️

I know, you want a quick answer, let’s summarize:

Node.js is a runtime environment that allows you to run JavaScript on the server side. It was created to solve the inefficiencies of traditional server technologies by using an event-driven, non-blocking I/O model, enabling to create scalable and high-performance network applications.

Inefficiencies node fixed:

  1. Thread-Based Request Handling: Traditional servers like Apache create a new thread for each incoming request. This consumes a lot of memory and can become inefficient under heavy load. Node.js, with its single-threaded event loop, can handle multiple requests concurrently without spawning new threads, reducing memory usage and improving performance.
  2. Blocking I/O Operations: In many traditional server environments, I/O operations (like reading files or querying databases) block the execution of code until they complete. This blocking can lead to performance bottlenecks. Node.js uses non-blocking I/O operations, allowing the server to handle other tasks while waiting for I/O operations to complete.
  3. Scalability Issues: Traditional servers can struggle to scale efficiently, especially when handling a high number of concurrent connections. Node.js’s event-driven architecture makes it easier to scale applications horizontally (by adding more servers) or vertically (by handling more operations within a single server).

Consider working with node because of it’s:

  1. Efficiency: Node.js’s non-blocking I/O operations and event-driven architecture make it extremely efficient, allowing it to handle numerous concurrent connections with minimal resources.
  2. Speed: Node.js’s single-threaded nature and non-blocking operations result in faster execution of code, especially for I/O-intensive tasks.
  3. Unified Programming Language: Developers can use JavaScript for both client-side and server-side development, streamlining the development process and reducing the context-switching between languages.
  4. Rich Ecosystem: Node.js has a vast ecosystem of libraries and frameworks available through npm (Node Package Manager), making development faster and easier.

Some examples of real world companies that uses node.js

Node.js powers many of the web applications and services we use daily. Se below three of them with the usage, reason and outcome after using node. 😎

LinkedIn:

  • Usage: LinkedIn switched from Ruby on Rails to Node.js for their mobile backend in 2011.
  • Reason: The switch to Node.js allowed them to handle a large number of simultaneous connections with high performance, which was crucial for their mobile app.
  • Outcome: The transition resulted in a significant reduction in the number of servers (from 30 to 3) and increased performance, handling more traffic with fewer resources.

Netflix:

  • Usage: Netflix uses Node.js to build its entire user interface (UI) layer.
  • Reason: Netflix chose Node.js for its fast startup time, performance, and ability to handle asynchronous I/O operations, which is ideal for a data-driven company that deals with real-time data streaming.
  • Outcome: The use of Node.js enabled Netflix to reduce the startup time of their applications, improve the performance of their server-side rendering, and enhance the overall user experience.

PayPal:

  • Usage: PayPal uses Node.js for both their client-side and server-side applications.
  • Reason: PayPal migrated from Java to Node.js to unify their engineering teams, allowing both browser and server applications to be written in JavaScript.
  • Outcome: The migration to Node.js resulted in a 35% decrease in the average response time for their pages and a reduction in the number of lines of code, leading to faster development cycles and improved application performance.

Conclusion

Node.js revolutionized server-side programming by leveraging JavaScript’s capabilities beyond the browser. By addressing the inefficiencies of traditional server technologies, Node.js enables developers to build scalable, high-performance applications with ease. Understanding why Node.js was created and its benefits can help you appreciate its role in modern web development.

🗒️We’ll go deeper, but while you wait:

Read my last post about streams in node: Unlocking the Power of Node js Streams: Your Ultimate Beginner’s Guide 🌟

Leave a Reply

Your email address will not be published. Required fields are marked *