Where Node.js Shines
Now that you know what Node.js is—a way to run JavaScript outside the browser—you might wonder what people actually build with it. This chapter takes a short tour of the kinds of software where Node.js is a great fit, and where it is not.
The Sweet Spot: Programs That Wait
Most of what computers do when they serve people over a network is waiting. They wait for a file to arrive from disk, wait for a database to answer, wait for data to come in over the internet. Waiting for things outside the computer is called input/output, or I/O for short.
Node.js is very good at programs that spend most of their time on I/O. Instead of sitting idle while one task waits, it can start another task. A single Node.js program can comfortably handle thousands of connections at once.
Where Node.js Is Used
Here are the most common kinds of real-world Node.js software:
- Web servers and APIs. Programs that answer requests from browsers and phone apps—serving pages, checking logins, sending data. This is Node.js's biggest use.
- Real-time chat and live updates. Because Node.js handles many connections at once cheaply, it powers chat apps, notifications, and collaboration tools.
- Build tools for websites. Even if a site never runs Node.js in production, its pages are often built and bundled using Node.js tools like webpack or Vite.
- Command-line tools. Scripts that automate tasks, since the same
nodecommand runs files directly. - Talking to other services. Programs that pull data from APIs, process webhooks (messages one service sends to another), or glue systems together.
Where Node.js Is Not the Best Fit
Being honest about limits helps you choose tools well:
- Heavy number crunching. Node.js mostly does one thing at a time, so tasks like video encoding or scientific math can block everything else. Other tools handle these better.
- Long-running CPU-heavy background work. Same reason: one slow calculation delays every waiting task.
Why This Matters for the Rest of the Course
The chapters ahead build toward a real web server—a program that listens on a network port and responds to requests. That is the classic Node.js use case, and every skill you learn (files, modules, asynchronous code) exists to serve that goal.
Exercise
You are asked to build a program that answers thousands of requests per second but only does simple lookups in a database. Is Node.js a good choice?
Show answer
Yes. This is I/O-heavy work with little computation, which is exactly what Node.js handles best. It can manage many waiting connections at the same time.
Exercise
Your program needs to resize thousands of large images, which takes real computing power on each one. Is Node.js the best first choice?
Show answer
Probably not, at least not by itself. Image resizing is CPU-heavy, and a single-threaded Node.js process would stall. A common solution is to do the resizing in a separate tool and keep Node.js for the web layer.
Spotted a mistake, or code that does not work?