Skip to main content

Command Palette

Search for a command to run...

Getting Started with Node.js: Installation, Setup, and Your First Program

Updated
28 min read
Getting Started with Node.js: Installation, Setup, and Your First Program

Introduction: Before You Write a Single Line

Every technology you have ever used on the internet — every website, every API, every real-time chat application — runs on a server somewhere. That server is just a computer running code, listening for requests, and sending back responses.

For a long time, if you wanted to write that server-side code, you had to learn a completely different language from what you used in the browser. Frontend developers wrote JavaScript in the browser. Backend developers wrote Python, Java, Ruby, or PHP on the server. If you wanted to do both, you had to be comfortable in at least two different languages.

Node.js changed that.

Node.js lets you run JavaScript outside of the browser — directly on your computer, on a server, anywhere. The same language you use to make buttons change color on a webpage can now be used to build the server that serves that webpage in the first place.

This article is about taking your very first steps with Node.js. We will install it, verify it works, understand how to interact with it directly, write our first JavaScript file, run it, and finally build a simple server — all without any frameworks, all from scratch.

By the end, you will have a working Node.js environment and a clear understanding of what is actually happening when you run your code.


Part 1: What Is Node.js, in Plain Terms

Before installing anything, it helps to understand what Node.js actually is, because there is a common misconception worth clearing up.

Node.js is not a programming language. JavaScript is the programming language. Node.js is a runtime environment — a program that can take your JavaScript code and execute it outside of a web browser.

To understand why this matters, consider how JavaScript normally works. When you write JavaScript for a webpage, you put it in a script tag and the browser runs it. The browser has a JavaScript engine built into it (Chrome uses one called V8, Firefox uses SpiderMonkey, and so on). That engine reads your JavaScript and turns it into instructions the computer can follow.

Node.js takes the V8 engine — the same one from Chrome — and packages it so that your computer can run JavaScript directly, without a browser involved at all. On top of that, Node.js adds capabilities that the browser does not have: the ability to read and write files on your hard drive, the ability to make and listen for network connections, the ability to interact with the operating system, and much more.

So when someone says they are a Node.js developer, they mean they are writing JavaScript that runs on a server or on their local machine, not in a browser.

That is the context. Now let us get it installed.


Part 2: Installing Node.js

Where to Get It

The official and only place you should download Node.js from is the official website:

https://nodejs.org

When you visit that page, you will typically see two download options presented prominently. It is worth understanding the difference between them before you click anything.

LTS (Long Term Support)

LTS stands for Long Term Support. This version is stable, thoroughly tested, and officially supported for an extended period — typically several years. Bug fixes and security patches continue to be released for it. If you are just getting started, if you are building something for work, or if you want a version that will remain reliable and supported, the LTS version is the right choice.

Current

The Current version includes the newest features in Node.js. It is updated more frequently and may include experimental features that have not yet made it into LTS. If you specifically need a feature that only exists in the latest version, you might choose this. Otherwise, LTS is the safer and more practical option.

For this article, and for most purposes, download the LTS version.

Installation by Operating System

The installation process is straightforward on every major operating system. The Node.js website automatically detects your operating system and offers the appropriate installer.

On Windows

Download the installer file with a .msi extension from the Node.js website. Run it. You will go through a setup wizard with a few screens. Accept the license agreement, choose an installation directory (the default is fine), and proceed through the wizard. One screen may ask about installing necessary tools — you can leave the default selection and continue.

When the installation completes, Node.js and npm (Node Package Manager, which comes bundled with Node.js) will both be installed.

On macOS

Download the installer with a .pkg extension from the Node.js website. Open it and follow the installation wizard. It is a standard macOS installation process — agree to the terms, select a destination, and install. You may be prompted for your administrator password.

Alternatively, if you use Homebrew (a popular package manager for macOS), you can install Node.js from the terminal:

brew install node

Both methods result in the same working installation.

On Linux

The approach depends on your Linux distribution. Most distributions have Node.js available through their package manager, but the version may be outdated. For the current LTS version, the Node.js website provides instructions specific to your distribution.

For Ubuntu and Debian-based distributions, the recommended approach is to use the NodeSource repository. The Node.js website provides the specific commands for setting this up. Generally it involves adding the NodeSource repository to your package manager and then installing with apt:

sudo apt-get install -y nodejs

For Fedora, Red Hat, and similar distributions, the process uses dnf or yum instead of apt.

If you are on Linux and prefer a version manager (discussed below), that is also an excellent option.

A Note About Version Managers

If you plan to work with Node.js seriously over time, it is worth knowing that version managers exist. Tools like nvm (Node Version Manager) allow you to install multiple versions of Node.js on the same machine and switch between them easily. This is useful when you work on different projects that require different Node.js versions.

For getting started, the direct installer from the Node.js website is perfectly fine. But as you grow as a developer, look into nvm — it will eventually save you time and frustration.


Part 3: Verifying the Installation

Installing software and assuming it worked is a habit to avoid. After any installation, verify it actually worked before moving forward. Nothing is more frustrating than spending twenty minutes writing code only to discover the environment was never set up correctly.

Open a terminal. On Windows, this is either Command Prompt or PowerShell. On macOS, it is the Terminal application, which you can find in Applications under Utilities, or by searching with Spotlight. On Linux, it is whatever terminal emulator your distribution provides.

Once your terminal is open, run these two commands:

node --version

and

npm --version

If Node.js is installed correctly, each command will print a version number. Something like:

v20.11.0

and

10.2.4

Your version numbers will likely be different, and that is fine. The exact numbers do not matter at this stage. What matters is that you get a version number rather than an error message.

If instead you see something like command not found or is not recognized as an internal or external command, then the installation did not complete correctly, or the installation directory was not added to your system's PATH. In that case, try restarting your terminal (or your computer) and running the commands again. If the problem persists, revisiting the installation steps or consulting the Node.js documentation for your specific operating system will resolve it.

When both commands return version numbers, you are ready to move forward.


Part 4: The Node.js REPL

Now that Node.js is installed, let us start using it. The first way to interact with Node.js is through something called the REPL.

What REPL Means

REPL stands for Read-Eval-Print Loop. It is an interactive programming environment that follows a simple cycle:

  • It reads what you type

  • It evaluates (executes) what you typed

  • It prints the result

  • It loops back and waits for your next input

REPLs are not unique to Node.js. Python has one, Ruby has one, many programming languages have one. They give you a way to run code immediately and see results without creating a file, without running a full program. They are excellent for experimentation, for testing small ideas, for quickly checking how something works.

Think of the REPL as a direct conversation with Node.js. You say something (type some code), it responds immediately (shows the result), and then it waits for you to say something else.

Starting the REPL

To start the Node.js REPL, open your terminal and type:

node

Just the word node, nothing after it. Press Enter.

The prompt in your terminal will change. Instead of your usual terminal prompt (which might be something like $ or > or your username), you will see:

>

That > is the REPL prompt. It means Node.js is running and waiting for you to type JavaScript.

Using the REPL

Let us try some things. Type each of the following and press Enter after each one:

1 + 1

Output:

2
'Hello' + ' ' + 'World'

Output:

'Hello World'
let name = 'Node.js'

Output:

undefined

This one might surprise you. When you declare a variable, the assignment itself does not produce a value, so the REPL shows undefined. But the variable is now stored. Try using it:

name

Output:

'I am learning ' + name

Output:

text
'I am learning Node.js'

You can also write more complex expressions:

Math.max(10, 45, 23, 87, 12)

Output:

87
[1, 2, 3, 4, 5].filter(num => num > 2)
[ 3, 4, 5 ]

Everything you know from JavaScript works here. The REPL is full JavaScript, with all Node.js capabilities available.

Multi-line Code in the REPL

You can write code that spans multiple lines. When you press Enter after a line that is not complete (like after opening a curly brace), the REPL shows ... instead of >, indicating it is waiting for more:

function add(a, b) {
... return a + b;
... }

After you close the function and press Enter on a blank line, the function is defined. Then you can call it:

add(5, 3)

Output:

8

Special REPL Commands

The REPL has a few special commands that start with a dot. The most useful ones for beginners are:

.help      Shows a list of all special REPL commands
.exit      Exits the REPL and returns to your normal terminal
.clear     Clears the current session and starts fresh

You can also exit the REPL by pressing Ctrl+C twice, or Ctrl+D once.

When to Use the REPL

The REPL is useful for quick experiments and checking your understanding of how something works. If you are not sure whether a particular JavaScript method does what you think it does, or you want to test a small piece of logic before putting it in a file, the REPL is perfect for that.

For actual programs and projects, you write code in files. That is what we will do next.


Part 5: Creating and Running Your First JavaScript File

The REPL is interactive and immediate, but real programs live in files. Let us write our first Node.js script as a file and run it.

Setting Up a Working Directory

Before creating files, let us create a proper place to put them. Good habits from the beginning save headaches later.

Open your terminal and navigate to wherever you keep your projects. This might be your Documents folder, a dedicated Projects folder, your desktop, or anywhere that makes sense to you. Then create a new directory for this work:

mkdir nodejs-basics
cd nodejs-basics

The mkdir command creates a new directory called nodejs-basics. The cd command moves you into that directory. Now you are inside a clean folder where you can create your files.

Creating the File

Create a new file called hello.js. You can do this in any text editor — Notepad on Windows, TextEdit on macOS, gedit on Linux, or any code editor like Visual Studio Code, Sublime Text, or Atom.

If you are using Visual Studio Code and have it set up with the code command, you can open the current directory directly from the terminal:

code .

Otherwise, open your editor of choice and create a new file, then save it as hello.js inside the nodejs-basics directory you just created.

Writing Your First Script

In hello.js, type the following:

console.log('Hello from Node.js');

Save the file.

That is the entire program. Simple, but let us make sure we understand it before running it.

console.log() is a function available in both the browser and Node.js. It takes whatever you pass to it and prints it to the output. In the browser, that output goes to the browser's developer console. In Node.js, that output goes to the terminal.

'Hello from Node.js' is the string we are passing to it. A string in JavaScript is any sequence of characters enclosed in quotes — single quotes, double quotes, or backticks all work.

Running the File

In your terminal, make sure you are in the nodejs-basics directory (if you just created it in the previous step, you should already be there). Then run:

node hello.js

You should see:

Hello from Node.js

That is it. That is a Node.js program running on your computer.

What happened: you told your operating system to run the node program, and you gave it hello.js as the file to execute. Node.js read your file, passed the JavaScript to the V8 engine, and the V8 engine executed it. The console.log call printed text to the terminal, and then the program ended because there was nothing else to do.

Expanding the Script

Let us make the script a bit more interesting to better understand what is available in Node.js:

// Basic output
console.log('Hello from Node.js');

// Variables
const currentTime = new Date();
console.log('Current time:', currentTime);

// String operations
const firstName = 'Ada';
const lastName = 'Lovelace';
const fullName = firstName + ' ' + lastName;
console.log('Full name:', fullName);

// A simple calculation
const hoursInADay = 24;
const minutesInAnHour = 60;
const minutesInADay = hoursInADay * minutesInAnHour;
console.log('Minutes in a day:', minutesInADay);

// Arrays
const languages = ['JavaScript', 'Python', 'Ruby', 'Go'];
console.log('Languages:', languages);
console.log('First language:', languages[0]);
console.log('Number of languages:', languages.length);

// A simple function
function greet(name) {
    return 'Welcome to Node.js, ' + name + '!';
}

console.log(greet('developer'));

Save this in hello.js and run it again:

node hello.js

Output:

Hello from Node.js
Current time: 2024-01-15T10:30:45.123Z
Full name: Ada Lovelace
Minutes in a day: 1440
Languages: [ 'JavaScript', 'Python', 'Ruby', 'Go' ]
First language: JavaScript
Number of languages: 4
Welcome to Node.js, developer!

Everything you see here is standard JavaScript, running directly on your machine through Node.js. No browser involved.

Node.js-Specific Features: Accessing the File System

Here is something you cannot do in browser JavaScript: read files from your computer. Let us try it.

Create a text file in your nodejs-basics directory called message.txt and put some text in it:

This text is coming from a file on my computer.
Node.js can read it directly.

Now create a new file called readfile.js:

const fs = require('fs');

fs.readFile('message.txt', 'utf8', function(error, content) {
    if (error) {
        console.log('Something went wrong:', error.message);
        return;
    }
    console.log('File contents:');
    console.log(content);
});

console.log('This line runs before the file is read');

Run it:

node readfile.js

Output:

This line runs before the file is read
File contents:
This text is coming from a file on my computer.
Node.js can read it directly.

A few things worth noting here.

require('fs') is how you bring in a built-in Node.js module. fs stands for file system. It is a module that comes with Node.js and provides functions for working with files. You do not need to install it — it is always available.

The last console.log runs before the file contents are printed. This is because fs.readFile is asynchronous — it starts reading the file and immediately returns, allowing the rest of the code to continue running. When the file reading is complete, the function you provided (the callback) is called with the results. This is a fundamental aspect of how Node.js works, and you will become very familiar with this pattern.


Part 6: Writing Your First HTTP Server

Now for the significant step: writing a server. This is where Node.js shows its real purpose. We are going to create a program that listens for incoming connections on your computer and responds to them, just like a real web server.

We will do this without any frameworks. Node.js has a built-in module called http that provides everything needed to create a basic server. Using it directly will give you a clear understanding of what is actually happening, without anything hidden behind framework abstractions.

What a Server Actually Does

Before writing code, let us be clear about what we are building.

A server is a program that runs continuously, waiting for requests. When a request comes in, the server reads it, decides what to do with it, and sends back a response. Then it goes back to waiting for the next request.

When you type a URL into your browser and press Enter, your browser sends an HTTP request to a server somewhere. That server processes the request and sends back an HTTP response, which your browser then displays.

We are going to build one of those servers, running locally on your computer.

The Code

Create a new file called server.js in your nodejs-basics directory:

const http = require('http');

const hostname = '127.0.0.1';
const port = 3000;

const server = http.createServer(function(request, response) {
    response.statusCode = 200;
    response.setHeader('Content-Type', 'text/plain');
    response.end('Hello World\n');
});

server.listen(port, hostname, function() {
    console.log('Server is running at http://' + hostname + ':' + port);
});

Before running it, let us go through every single line so nothing is mysterious.

Breaking Down the Code

Line 1: Importing the http module

const http = require('http');

Just like fs for file system, http is a built-in Node.js module for working with the HTTP protocol. require('http') loads that module and gives us access to all its functionality. We store it in a variable called http.

Lines 3 and 4: Configuration

const hostname = '127.0.0.1';
const port = 3000;

127.0.0.1 is a special IP address that always refers to your own computer. It is called localhost. When your server listens on this address, it will only receive requests from the same machine — your own browser, for instance. When you deploy a real server, this would be different, but for local development, 127.0.0.1 is what you want.

Port 3000 is a number that distinguishes this server from other programs on your computer that might also be communicating over the network. Think of your computer's IP address as a building address, and ports as apartment numbers within that building. Port 3000 is just a conventional choice for development servers. You could use many other port numbers — 8080, 4000, 5000 are all commonly used for development.

Lines 6 through 10: Creating the server

const server = http.createServer(function(request, response) {
    response.statusCode = 200;
    response.setHeader('Content-Type', 'text/plain');
    response.end('Hello World\n');
});

http.createServer() creates a new server object. We pass it a function, and that function is called every single time a request comes in. It is called with two arguments: request and response.

request contains all the information about the incoming request — what URL was asked for, what method was used (GET, POST, etc.), what headers were sent, and more.

response is the object you use to build and send back your response.

response.statusCode = 200 sets the HTTP status code. Status code 200 means "OK" — everything worked fine. You have probably seen 404 (Not Found) before. There are many status codes, each meaning something different.

response.setHeader('Content-Type', 'text/plain') sets a response header telling the browser what kind of content is being sent back. text/plain means plain text. If you were sending HTML, this would be text/html. If you were sending JSON, it would be application/json.

response.end('Hello World\n') sends the response body — the actual content — and signals that the response is complete. Whatever string you pass here is what the browser will receive.

Lines 12 through 14: Starting the server

server.listen(port, hostname, function() {
    console.log('Server is running at http://' + hostname + ':' + port);
});

Creating a server does not automatically start it. server.listen() actually starts the server — it tells Node.js to start accepting incoming connections on the hostname and port we specified.

The function passed to server.listen() is a callback that runs once, when the server has successfully started and is ready to accept connections. We use it here to print a confirmation message to the terminal so we know the server is running.

Running the Server

In your terminal, from the nodejs-basics directory, run:

node server.js

You should see:

Server is running at http://127.0.0.1:3000

Notice that the terminal does not return to its normal prompt. The program is still running, waiting for connections. This is different from hello.js, which ran, printed output, and ended. A server runs continuously until you stop it.

Visiting Your Server

Open a web browser — any browser will do. In the address bar, type:

http://127.0.0.1:3000

Or equivalently:

http://localhost:3000

(localhost is a hostname that your computer knows means 127.0.0.1)

Press Enter. You should see:

Hello World

In plain text, in the browser window. Your server received the request and sent back a response, and your browser displayed it.

Meanwhile, in your terminal, you can see the server is still running, waiting for the next request. You can visit the URL again and again, and each time the server responds.

To stop the server, go back to your terminal and press Ctrl+C. The server shuts down, and your terminal returns to its normal prompt.

Making the Server More Detailed

Our first server responds with the same thing no matter what. Let us make it slightly more informative by looking at the incoming request:

const http = require('http');

const hostname = '127.0.0.1';
const port = 3000;

const server = http.createServer(function(request, response) {
    
    // Log each incoming request to the terminal
    console.log('Received request:');
    console.log('  Method:', request.method);
    console.log('  URL:', request.url);
    console.log('  Time:', new Date().toISOString());
    
    // Build a response based on the URL
    if (request.url === '/') {
        response.statusCode = 200;
        response.setHeader('Content-Type', 'text/plain');
        response.end('Welcome to the homepage');
        
    } else if (request.url === '/about') {
        response.statusCode = 200;
        response.setHeader('Content-Type', 'text/plain');
        response.end('This is the about page');
        
    } else {
        response.statusCode = 404;
        response.setHeader('Content-Type', 'text/plain');
        response.end('Page not found');
    }
});

server.listen(port, hostname, function() {
    console.log('Server is running at http://' + hostname + ':' + port);
    console.log('Try visiting:');
    console.log('  http://' + hostname + ':' + port + '/');
    console.log('  http://' + hostname + ':' + port + '/about');
    console.log('  http://' + hostname + ':' + port + '/anything-else');
});

Run this updated server:

node server.js

Now try visiting these URLs in your browser:

http://localhost:3000/
http://localhost:3000/about
http://localhost:3000/contact

Each URL returns a different response. The first two return 200 with appropriate messages. The third (and any other path) returns 404 with "Page not found".

Watch your terminal as you visit each URL. You will see the request details being logged each time.

This is a very basic form of routing — deciding what to respond with based on what was requested. Real frameworks like Express.js make routing much more convenient, but they are doing the same fundamental thing underneath.

Responding with HTML

Currently our server sends plain text. Let us send actual HTML so the browser renders it as a webpage:

const http = require('http');

const hostname = '127.0.0.1';
const port = 3000;

const server = http.createServer(function(request, response) {
    
    if (request.url === '/') {
        response.statusCode = 200;
        response.setHeader('Content-Type', 'text/html');
        
        const htmlContent = `
            <!DOCTYPE html>
            <html>
                <head>
                    <title>My First Node.js Server</title>
                </head>
                <body>
                    <h1>Hello World</h1>
                    <p>This page is being served by Node.js.</p>
                    <p>No frameworks. No libraries. Just Node.js.</p>
                    <a href="/about">Go to About page</a>
                </body>
            </html>
        `;
        
        response.end(htmlContent);
        
    } else if (request.url === '/about') {
        response.statusCode = 200;
        response.setHeader('Content-Type', 'text/html');
        
        const htmlContent = `
            <!DOCTYPE html>
            <html>
                <head>
                    <title>About - My First Node.js Server</title>
                </head>
                <body>
                    <h1>About This Server</h1>
                    <p>This server was written from scratch using Node.js.</p>
                    <p>It uses the built-in http module and nothing else.</p>
                    <a href="/">Go back home</a>
                </body>
            </html>
        `;
        
        response.end(htmlContent);
        
    } else {
        response.statusCode = 404;
        response.setHeader('Content-Type', 'text/html');
        
        const htmlContent = `
            <!DOCTYPE html>
            <html>
                <head>
                    <title>404 - Not Found</title>
                </head>
                <body>
                    <h1>404 - Page Not Found</h1>
                    <p>The page you are looking for does not exist.</p>
                    <a href="/">Go back home</a>
                </body>
            </html>
        `;
        
        response.end(htmlContent);
    }
});

server.listen(port, hostname, function() {
    console.log('Server running at http://' + hostname + ':' + port);
});

The only change from the plain text version is that we changed Content-Type from text/plain to text/html and we are now sending actual HTML markup. When the browser sees text/html in the Content-Type header, it knows to render the content as a webpage rather than displaying it as raw text.

Run it, visit http://localhost:3000, and you will see a proper webpage with a heading, paragraphs, and a working link that navigates to the About page.

Part 7: Understanding What You Have Built

Let us step back and look at the complete picture of what you have accomplished and what it means.

The File Structure

Your nodejs-basics directory now contains:

nodejs-basics/
    hello.js
    readfile.js
    message.txt
    server.js

Each file demonstrated something different:

hello.js showed that Node.js can execute JavaScript directly, access JavaScript's built-in capabilities like Date and Math, and print output to the terminal.

readfile.js showed that Node.js can interact with your computer's file system — something browser JavaScript cannot do. It also introduced the concept of asynchronous, callback-based code.

server.js showed the core capability of Node.js for web development: creating an HTTP server that listens for requests and sends responses.

What Makes This a "Server"

When your server.js is running and you visit http://localhost:3000 in your browser, here is exactly what happens:

Your browser sends an HTTP request to 127.0.0.1 on port 3000. Node.js, which is listening on that address and port, receives the request. The callback function you provided to http.createServer() is called with the request details. Your code examines the request and builds a response. The response is sent back to your browser. Your browser receives and displays the response.

This is the same sequence that happens when you visit any website. The scale is different — real servers handle millions of requests, have complex routing and business logic, read from databases, cache responses, and much more — but the fundamental mechanism is identical to what you just built.

The Difference Between Running a Script and Running a Server

This distinction is worth being explicit about.

When you run node hello.js, the program executes its code from top to bottom, and when it reaches the end, it exits. The Node.js process ends. Your terminal returns to its normal state.

When you run node server.js, the program starts the server with server.listen(), which tells Node.js to keep running and keep listening for connections. The program does not end when it reaches the bottom of the file because it has registered an ongoing listener. It will continue running until you explicitly stop it with Ctrl+C.

This is an important mental model: servers are long-running processes, not scripts that run once and exit.


Part 8: Common Beginner Mistakes and How to Handle Them

As you start working with Node.js, you will likely encounter a few common issues. Knowing about them ahead of time will save you time.

Port Already in Use

If you try to start your server and see an error like:

Error: listen EADDRINUSE: address already in use 127.0.0.1:3000

It means something else on your computer is already using port 3000. Usually this means you have another instance of your server running in a different terminal window, or you forgot to stop the previous one before restarting.

To fix this: find and close the other terminal window that is running Node.js, or stop the process running on that port. Alternatively, change the port number in your code to something else like 3001 or 4000.

Forgetting to Save the File

This sounds obvious, but it is one of the most common reasons code does not behave as expected. After making changes to a file, save it before running it with Node.js. Node.js reads the file at the time you run it — unsaved changes are not included.

Changes Not Taking Effect in the Server

When you change server.js and want to see the effect, you need to stop the server (Ctrl+C) and start it again (node server.js). Unlike a browser where you can just refresh the page, a running Node.js server loads your file once when it starts. It does not automatically reload when the file changes.

This gets tedious during development, which is why developers often use a tool called nodemon that automatically restarts the server when it detects file changes. But for now, manually stopping and restarting is perfectly fine and helps you understand what is happening.

The require Path for Built-in vs Local Modules

When you use require with a plain name like require('http') or require('fs'), Node.js knows these are built-in modules and finds them automatically.

When you use require to load a file you created, you need to use a path starting with ./ to indicate it is a local file:

// Built-in module - no path needed
const http = require('http');

// Your own file - path required
const myModule = require('./mymodule');

Forgetting the ./ when loading local files is a common mistake that results in a "Cannot find module" error.


A Complete Quick Reference

Here is a summary of everything covered, as a reference you can come back to:

Installing Node.js

Download from https://nodejs.org
Choose the LTS version
Run the installer for your operating system

Verifying installation

node --version
npm --version

Starting the REPL

node

Exiting the REPL

.exit
or Ctrl+C twice
or Ctrl+D once

Running a JavaScript file

node filename.js

Basic Node.js script

console.log('Hello from Node.js');

Reading a file

const fs = require('fs');
fs.readFile('filename.txt', 'utf8', function(error, content) {
    console.log(content);
});

Creating a basic HTTP server

const http = require('http');

const server = http.createServer(function(request, response) {
    response.statusCode = 200;
    response.setHeader('Content-Type', 'text/plain');
    response.end('Hello World');
});

server.listen(3000, '127.0.0.1', function() {
    console.log('Server running at http://127.0.0.1:3000');
});

Stopping a running server

Ctrl+C

Conclusion: What Comes Next

You now have a working Node.js environment and a genuine understanding of the fundamentals. You have installed Node.js, confirmed it works, used the REPL to experiment with code interactively, written JavaScript files and run them from the terminal, and built an HTTP server from scratch that responds to browser requests.

These are not trivial things. Many developers skip the fundamentals and jump straight to frameworks, which means they often do not understand what the framework is actually doing for them. By building a server with the raw http module, you have seen exactly what is involved: listening on a port, reading the incoming request, setting response headers, and sending back content.

From here, there are several natural next steps. You could explore more of Node.js's built-in modules — path for working with file paths, os for operating system information, events for the event emitter pattern. You could learn about npm (Node Package Manager) and how to install and use third-party packages. You could start exploring Express.js, which is a framework that makes building servers much more convenient by handling the routing and request parsing boilerplate for you.

But no matter which direction you go from here, you have the foundation. You know what Node.js is, how it runs, and how a basic server works. That understanding will serve you well as you continue learning.