In this quick tutorial, you will start Node.js tutorials with a Hello World program. You will learn how to set up the environment and write your first code
Table of Content
Setting up Node.js Environment
You can install Node.js from the official site and pick the LTS version. You can also add npm, which comes inside Node.js, and you use it to manage packages.
So let’s check the installation by typing:
node -vAnd
npm -vThese commands show the current version of Node.js and npm on your system.
You can create a new folder for your project and open it in your code editor. This folder holds your code and any files you add later.
Then, run this command to init the project:
npm init
#OR
npm init -yThis will create package.json file that is the map of the project that will store all modules you use.
Write Your First Hello World Program in Node.js
Inside the folder, make a new file named app.js. You write the code below inside that file.
console.log("Hello World");Then, open the terminal inside the project folder and type:
node app.jsThis command runs the file and prints Hello World on the screen.
You can change the text in the code and run it again to see a new output.
Create a Hello World Example for the Browser through Web Server
Inside the same folder, make a new file named server.js. Add the code below inside it.
const http = require("http");
const server = http.createServer((req, res) => {
res.writeHead(200, { "Content-Type": "text/plain" });
res.end("Hello World");
});
server.listen(3000, () => {
console.log("Server run at http://localhost:3000");
});This code starts a small server on port 3000 and sends Hello World as plain text to any browser.
Open a browser and go to http://localhost:3000 and you see the text Hello World from your Node.js server.

Wrapping Up
You learned how to set up Node.js and create a folder for your first code, and run a Hello World program.
Here is a quick recap:
- Install Node.js
- Check the version
- Make a folder for the project
- Create a file with
app.js - Write console.log
- Run it with node.
FAQs
How do I write a Node.js Hello World program?
// Create a file named app.js
console.log("Hello World");
Steps:
- Install Node.js from official site
- Create a new file
app.js - Add
console.log("Hello World"); - Run with
node app.js
How do I run Node.js Hello World in terminal?
// Inside terminal
node app.js
Explanation:
- Navigate to the folder where
app.jsis located - Run command
node app.js - Output will display: Hello World
Why is Hello World important in Node.js?
- It introduces you to the Node.js runtime
- Shows how
console.logoutputs to terminal - Builds confidence for writing more complex programs
Can I create a Node.js Hello World web server?
const http = require('http');
http.createServer((req, res) => {
res.write("Hello World");
res.end();
}).listen(3000);
Steps:
- Create a file
server.js - Add the above code
- Run with
node server.js - Visit http://localhost:3000 to see Hello World
Similar Reads
This article shows how Node.js creates HTTP servers. It covers requests, responses, routes, HTML, JSON, and gives examples for both…
This guide shows Node.js modules, how they work, how to import and export them, and why you use them. What…
What is Nodejs? Node.js is a powerful cross-platform JavaScript runtime that enables developers to execute JavaScript code on the server-side.…
Node.js file system lets you read, write, update, and manage files and folders with built-in methods. Understand the Node.js File…
Installing node js on Windows, Ubuntu, or macOS. You need to pick the version of Node.js that you want to…
Streams pass data in parts, so the app stays fast. This article explains Node.js Streams and how to use them.…
Node.js REPL runs JavaScript code in an instant test space inside your terminal. What is Node.js REPL? Node.js REPL is…
NVM (Node Version Manager ) is a command-line tool used to manage multiple versions of Node.js on a single machine.…
Node Package Manager (NPM) is an essential tool at the heart of the Node.js ecosystem. This is the defacto package…
Node JS Buffers store raw binary data in memory. This guide shows how to create them, work with them, and…