Skip to main content

Command Palette

Search for a command to run...

What is Node.js? JavaScript on the Server

Updated
9 min readView as Markdown
What is Node.js? JavaScript on the Server

Javascript entered the scene of web technology in 1995, by Brendan Eich at Netscape communications. If anyone says they knew how much importance it would garner, they'd be lying. JS, as we in the biz call it, is now ubiquitous in development process of the web, if not all the technology at this point. But, what made it so was a hobby project of sorts, by a man living in Cologne, Germany. What is it that enabled them?

Node.js

But before we could advance with node.js, we must understand why JS needed it.

Javascript and its quirk

Javascript was first developed to integrate interactivity and dynamic element, such as form-handling, complex animations to static sites. But, at first it was simply for the web, or limited to be executed in the browser only.

The devs at the time never imagined using JS for server logic. In that era, running code on the server meant using languages like PHP, Java, or C. JavaScript in the browser was like a restaurant waiter taking orders and serving up pages – it had a very client-side role. Node.js changed that by letting “waiters” (browser JS) now also play chef (server code). Node’s big, perhaps the biggest selling point was its ability to run JS “outside the realms of the browsers”.

Enter Node.js: Bringing JavaScript to the Server

Before we begin this section, I would love to clarify that Node.js, Nodejs, Node are all synonymous. Do not get distracted by the representation of names.

With Node.js, Ryan Dahl essentially built a tiny-local server engine. He was motivated by simple frustrations, I wish I were too, for example, watching a slow Flickr upload progress bar and wanted a better way to handle lots of I/O tasks.

Thus Nodejs came into existence.

Node.js uses Chrome’s V8 engine under the hood, so it compiles your JavaScript to fast machine code before running it. Instead of the old model (one thread per request), Node starts a single thread with an event loop. I/O operations (reading a file, querying a database, making a network call) are done non-blocking: the code “kicks off” the task and keeps running without waiting. When each I/O task finishes, its callback is queued. In practice this means one Node process can handle many requests at once. As Node’s docs explain, the event loop offloads work to the system kernel, so even with one thread Node can do non-blocking I/O.

V8 Engine: JavaScript’s Powerhouse

  • Node’s speed comes from Google’s V8 engine, a highly optimized JS engine written in C++. V8 takes your JavaScript and compiles it into native machine code before executing.

  • This Just-In-Time (JIT) compilation means loops and functions run very fast, often close to the speed of traditionally compiled languages. In other words, when your Node app runs, V8 is silently translating your JS into optimized CPU instructions behind the scenes.

  • This is why Node.js can handle heavy workloads; it’s not interpreting JS line-by-line like a slow script, but running fast, compiled code on the server.

Event-Driven Architecture

  • Node.js relies on a single-threaded, event-driven design. Think of the Node process as an office with one worker who never stops to “wait”. When it needs to do I/O (like read a file or call an API), it tells the OS to handle it and moves on to the next task. When the OS is done, it rings a bell and Node handles the result. This loop of events means the server isn’t idling.

  • In practice, Node can juggle thousands of connections because it doesn’t spawn a new thread for each one. Instead, it uses callbacks: each completed operation triggers its callback function.

  • As the Node documentation puts it, Node performs non-blocking I/O by delegating tasks to the kernel and then processing callbacks when they finish. The upshot is a highly scalable, low-latency system: I/O tasks never block each other, so hundreds of clients can be served in real time without delay.

Browser JS vs Server JS: An Analogy

  • Picture this: Browser JavaScript is like a waiter at a restaurant, taking orders (user clicks) and serving dishes (updating the web page). It works right in front of the customer (the user), making sure the UI is responsive. Node.js (server JavaScript) is like the kitchen staff.

  • It handles all the behind-the-scenes work: cooking meals (processing data), managing inventory (database access), and preparing orders for delivery. Both use the same language (JavaScript), but the roles differ. The waiter and the chef speak the same language; one interacts with the diners (browser), the other handles the orders in the back (server).

  • This analogy shows how JavaScript plays two roles: one on the client side in browsers, and one on the server side in Node.js.

Real-World Uses of Node.js

  • Node.js has found its niche where fast I/O and real-time updates matter. It’s ideal for real-time apps (like chat, live collaboration, online gaming) and streaming services (audio/video) because it can push data to clients instantly. Many big companies use Node in production.

  • For example, Netflix and PayPal rewrote parts of their backend in Node.js; PayPal found the Node team was able to build their services faster and catch up with Java teams using far fewer developers. LinkedIn moved its mobile API backend from Ruby to Node and went from 15 servers down to just 4, while improving response times. Walmart, Uber, and even NASA have large Node.js deployments for handling massive traffic spikes and real-time data.

  • In general, any service that involves many users making simultaneous requests (social feeds, online games, chat apps, IoT backends, etc.) is a great fit for Node.js. Its vast package library (npm) also means developers can pull in pre-built modules for almost any feature, from web frameworks to database connectors.

Node.js vs Traditional Backends

  • Unlike traditional server stacks (PHP/Apache or Java/Spring), Node’s runtime model is different.

  • For example, PHP typically handles each web request by spinning up a new process or thread, doing its work, then exiting. Java web servers also commonly use multiple threads (one per connection). Node.js, by contrast, handles all connections in one thread using the event loop.

  • This makes Node lightweight in terms of memory and context-switching: it can manage thousands of connections with minimal overhead. It also means the whole development stack can use one language (JS) instead of juggling PHP or Java on the server and JS in the browser. In short, Node’s approach trades threads for asynchronous callbacks, which often yields better performance for I/O-bound workloads.

  • So, ...I picked up this from other sources, I don't have much experience in PHP/Apache.

Runtime vs Language: Node and JavaScript

  • It’s important to clarify terminology: Node.js is not a new language, it’s a runtime environment for JavaScript.

  • JavaScript itself remains the language (syntax, keywords, etc.), the same one invented by Brendan Eich in 1995. What Node provides is the ability to execute JS code on the server (outside the browser).

  • Think of Node.js as a kitchen that speaks JavaScript – it lets the same language run in a different place. In other words, developers write JavaScript code in both environments, but “browser JS” has APIs like the DOM for page interaction, while “Node.js” adds APIs for networking and file systems. This distinction – language vs runtime – helps avoid confusion.

    Feature Browser JavaScript Node.js
    Execution Environment Client-side (in the browser). Server-side (outside the browser).
    Primary Focus User interaction and UI rendering. Logic-building, APIs, and data processing.
    Engine Varies by browser (V8 for Chrome/Edge, SpiderMonkey for Firefox, etc.). Exclusively built on Google's V8 engine.
    Global Object window or self. global.

Why Developers went crazy for Node.js

Developers adopted Node.js enthusiastically, why, because:

  • Full-Stack JavaScript: With Node, teams can use one language on both client and server. This unifies development, allows code reuse, and makes hiring easier because everyone speaks JavaScript.

  • Non-Blocking Performance: Node’s event-driven model keeps servers responsive. It is especially efficient at handling lots of I/O at the same time. Developers building chat servers, live dashboards, or streaming platforms found Node could handle thousands of open connections without bogging down.

  • Speed (V8 Engine): Google’s V8 makes Node very fast at running JavaScript. Functions and loops are JIT-compiled to machine code, so Node apps often perform as well as those written in faster languages for I/O-heavy tasks.

  • Huge Ecosystem (npm): Node’s package manager (npm) is enormous. Developers can pull in libraries for almost anything – web servers, database clients, authentication, you name it. This means less “reinventing the wheel” and faster development. This one's awesome.

  • Vibrant Community: Node has a large, active community. There are countless tutorials, frameworks (like Express, Koa), and tools. Companies backing Node (like Joyent, IBM, Google) and using it in production also give confidence that it’s here to stay.

  • Proven at Scale: Major tech companies use Node for serious workloads. Netflix, Uber, LinkedIn, PayPal, and Walmart all have public stories about using Node in production. This track record reassures developers that Node can handle real-world traffic and grow with their needs.

Together, these factors – one language everywhere, fast I/O, and a rich ecosystem – explain why many developers “went Node” when it first came out, and why Node.js remains a popular choice today.

When to Use Node.js

  • Real-Time and Streaming Apps: Use Node.js for chat systems, multiplayer games, streaming media, or any app that needs instant updates. Its non-blocking I/O and event loop excel at pushing real-time data to clients.

  • APIs and Microservices: Node is great for building RESTful APIs or microservices. You can quickly spin up an HTTP server in a few lines of JS, and npm lets you add JSON parsing, security, and other middleware easily.

  • CLI Tools and Automation: Because Node is lightweight and cross-platform, many developers use it to write command-line tools, build scripts, or automation tasks.

  • Not for CPU-Heavy Tasks: Node’s single-threaded design means pure JavaScript can’t easily utilize multiple cores for heavy computation. For CPU-bound jobs (image processing, large calculations), you might offload to worker processes or use another language better suited to parallel compute.

Summary

Node.js opened the door for JavaScript to run everywhere. Its creators solved the need for a fast, scalable server-side JS, and developers embraced it for the productivity and performance it brought. Today, Node.js is a key part of many of my, if not all projects. And this is true for millions of devs around the world.