What is Node.js?
That’s everything you need know about Node.js. If you’re eager to start programming, skip ahead to Chapter 2. That said, it’s worth revisiting this chapter later to learn about Node’s advantages and core features.
JScript in Internet Explorer.
Work then started on ECMAScript 6—or “ES6”. The final specification was approved in 2015, which led to yet another name: “ES2015”. New specifications now arrive every year.
The Node Package Manager (npm) was introduced in 2010. It allowed developers to use code modules published by others in their own projects. There was no official ECMAScript module standard at the time, so Node.js and npm adopted CommonJS.
The first (non-beta) release of Node.js arrived in 2015, with updates promised every six months.
Why Learn Node.js?
Below, we’ll look at some of the reasons you should consider using Node.js.
Server-side languages are more diverse. Historically, developers could opt for PHP, Ruby, Python, C# (ASP.NET), Perl, or Java, but these have different syntaxes and concepts. It can be difficult to switch contexts, so larger project teams often split into frontend and backend developers.
Most server-side languages are fast enough, but few match the speed of Node.js. The V8 engine is quick, and it evolves rapidly, having the weight of Google and Chrome behind its development. Node.js also has a non-blocking, event-driven I/O.
Let’s go through that again with less jargon. Most languages use synchronous blocking execution. When you issue a command—such as fetching information from a database—that command will halt further processing and complete before the runtime progresses to the next statement. To ensure that multiple users can have access at the same time, web servers such as Apache create a new processing thread for every request. This is an expensive operation, and Apache has a default limit of 150 concurrent connections. Busy servers can become overloaded.
Asynchronous programming has challenges, but it’s possible to create fast Node.js applications that scale well.
Web platform features such as WebSockets and server-sent events permit real-time functionality—such as instant data updates, live chat, multiplayer games, and more. These can be difficult to implement in traditional server-side languages, where they often require third-party services. Real-time functionality in Node.js is significantly easier.
The Node.js runtime is small and cross-platform. As well as catering for Linux, macOS, and Windows, you find editions for embedded systems, the Raspberry Pi, and even SpaceX rockets.
Node offers a minimal standard library with good documentation. It contains basic functions for error handling, file system access, network operations, and logging.
For everything else …
Node.js has the largest package registry in the world, with more than one million modules. You’ll find pre-written code for task runners, loggers, database connectors, image processors, code compilers, web servers, API managers, and even client-side libraries.
The npm command-line tool is provided with Node.js and makes it easy to install, update, and remove modules. You can also use it to install global modules so Node.js scripts can run as commands from anywhere on your system.
It’s Open Source
Node.js is an open-source project. The runtime is free to use without any commercial restrictions. The majority of modules are also free, because they’re submitted by the community for the benefit of other developers.
This course concentrates on web applications, but you can use Node.js to create serverless functions, deployment scripts, cross-platform command-line tools, and even complex graphical apps such as VS Code, Slack, and Skype—all of which use the Electron framework.
As a web developer, you’ll almost certainly encounter Node.js, even if it’s not a core part of your technology stack. Knowing a little Node.js could help your projects and career. You’ll have a better insight into the possibilities available to modern web applications.
What About Deno?
Deno smooths over some cracks and inconsistencies of Node.js, with the benefit of a decade’s worth of hindsight. It directly supports TypeScript without a compiler, uses ES6 modules rather than CommonJS, replicates many browser APIs (
Fetch, Web Workers, etc.), and provides built-in tools for linting, testing, and bundling.
Deno is great—but it’s new, and yet to achieve a fraction of Node’s popularity. The frameworks are similar: if you know one, it’s easy to switch to the other.
Many chapters in this course end with a quick quiz to ensure you’ve grasped the concepts. Beware! Some questions are designed to catch you out, so make sure you’ve been paying attention!