Introduction to Node.js and its use cases
🎯 Introduction
By the end of this article, you will be able to decide when you need Node.js and run a JavaScript file from the terminal.
🧱 JavaScript is the language; Node.js runs it
Node.js is a JavaScript runtime: a program that executes JavaScript and provides supporting capabilities. Once installed, it lets you run .js files directly on your computer without first creating a web page.
You can use the JavaScript syntax you already know. Node.js adds capabilities such as reading and writing local files, receiving network requests, and running development tools.
Node.js uses the V8 engine to parse and execute JavaScript. Chrome uses the same engine. Sharing an engine does not mean sharing every capability: each runtime provides its own access to pages and files.
⚖️ Moving from the browser to Node.js changes the available APIs
Node.js has no browser page, so window and document are unavailable. Built-in modules let you read and write files and directories within the permissions of the operating system user.
globalThis provides access to the global object in both environments, but their members are not identical. Variables declared in regular modules do not automatically become global properties. Use module imports and exports to share functionality between files.
In Node.js, start with these two additional capabilities:
- process provides information about the current process. A process is a running instance of a program; this object exposes startup arguments, environment variables, and exit status.
- Buffer holds bytes from files and network transfers, allowing you to work with text encodings, images, and other binary content.
Both objects are available directly; their dedicated articles explain how to use them. Other built-in capabilities, such as file and path operations, require importing the appropriate module, with no npm installation needed.
💡 What can you build with Node.js?
Web services: provide data to a page
A web service is a program that keeps receiving network requests and returning results. For example, when a page requests a user profile, Node.js receives the request, retrieves the required information, and returns data. The page handles display; Node.js handles requests.
You will implement this in the Node.js backend development course. This fundamentals course first covers the modules, file operations, and asynchronous capabilities it relies on.
CLI: operate tools through commands
A CLI is a command-line interface that lets users operate a tool by entering commands in a terminal. A project creation tool can read a project name, generate directories and files, and report results in the terminal. Running these development tools is often why frontend developers install Node.js.
Automation scripts: repeat tasks programmatically
Scripts can organize files according to rules, generate file lists, or check configuration. Run one, and it exits when its task is done. “Automation script” describes the work performed, while “CLI” describes how users interact with it. One program can be both.
Desktop applications: access local resources with a desktop framework
Electron is a framework for building desktop windows with web technologies. It can use Node.js for tasks such as handling local files, but Node.js alone does not provide desktop windows. Continue with the Electron course if you need this functionality.
🛠 Run a JavaScript file
The examples in this course use Node.js 24.19.0. Built-in features require no third-party packages. If Node.js is not installed, complete the setup guide, then return here.
Create an empty directory and save the following as hello.mjs:
console.log('Hello, Node.js')
Open that directory in your terminal and run:
node hello.mjs
The terminal prints Hello, Node.js, then the program exits.
This example confirms that you can run a file. Running programs explains how to accept input so that a script can perform different tasks based on its arguments.
❓ Questions and answers
Q1: Is Node.js a backend framework?
No. It is a runtime. Backend frameworks build on it to provide features such as request handling.
Q2: Do I need to buy a server to use Node.js?
No. You can learn, process files, and run local tools on your own computer.
Q3: Can I run browser code unchanged in Node.js?
Pure language logic often works, but code that uses browser APIs such as document needs changes.
🧪 Exercise
Find an operation in your existing frontend code that depends on the browser environment. Add a comment explaining why it cannot run unchanged in Node.js, and whether it concerns the page, files, or the network.
// Write your code here
🎉 Try these techniques with your own examples!
