,

NodeJS Hello World

Posted by


Node.js is a powerful server-side JavaScript runtime that allows developers to build fast and scalable web applications. In this tutorial, we will guide you through the process of creating a simple "Hello, World!" application using Node.js.

Step 1: Install Node.js
Before you can start building Node.js applications, you need to install Node.js on your computer. To do this, visit the official Node.js website (https://nodejs.org/) and download the appropriate version for your operating system. The installation process is straightforward and usually involves clicking through a series of prompts.

Step 2: Create a new Node.js project
Once Node.js is installed on your computer, you can create a new Node.js project by opening a terminal window and navigating to the directory where you want to create your project. To do this, run the following command:

mkdir hello-world-nodejs
cd hello-world-nodejs

Step 3: Create a new JavaScript file
In the hello-world-nodejs directory, create a new JavaScript file called app.js. This file will contain the code for our "Hello, World!" application. To create a new JavaScript file, run the following command:

touch app.js

Step 4: Write the code for the application
Open the app.js file in your favorite text editor and add the following code:

const http = require('http');

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

const server = http.createServer((req, res) => {
  res.statusCode = 200;
  res.setHeader('Content-Type', 'text/plain');
  res.end('Hello, World!n');
});

server.listen(port, hostname, () => {
  console.log(`Server running at http://${hostname}:${port}/`);
});

This code creates a simple HTTP server that listens on port 3000 and responds with "Hello, World!" when a request is made.

Step 5: Start the application
To start the application, run the following command in the terminal:

node app.js

You should see the message "Server running at http://127.0.0.1:3000/" in the terminal. This means that the application is running and ready to accept requests.

Step 6: Test the application
Open a web browser and navigate to http://127.0.0.1:3000/. You should see the message "Hello, World!" displayed in the browser. Congratulations, you have successfully created a "Hello, World!" application using Node.js!

In this tutorial, we walked you through the process of creating a simple "Hello, World!" application using Node.js. Node.js is a versatile and powerful platform for building web applications, and we encourage you to explore its capabilities further. Happy coding!

0 0 votes
Article Rating
28 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
@NikhilMehta-c6q
30 days ago

node hello.js likhne pr console.log me jo word likhe h nhi aa rhe hai

@ExtraAccount-e8l
30 days ago

Thankyou Sir

@deepanshumishra7518
30 days ago

nicely explained.

@RohitVerma-si1jo
30 days ago

very helpful video bro

@raghavgauri02
30 days ago

crystal clear 😍

@codewithvinod9033
30 days ago

awesome

@BhagatBhutale..
30 days ago

Video useful

@priyankmoon3274
30 days ago

Brother thank you for this playlist

@abhayshukla7471
30 days ago

BHAI YEH EMPTY FOLDER BANAYA KAHA HAI ?? git pe??

@karanbatra
30 days ago

thankyou bhaiya

@pratikbhatt8793
30 days ago

This is perfect for learning NodeJs and understanding deeply the concepts.

@hacks1712
30 days ago

Awsome brother!! subscribed your channel

@SHANMUKASRINIVAS-l3o
30 days ago

PS D:NODE JS> node express-server.js

node:internal/modules/cjs/loader:1143

throw err;

^

Error: Cannot find module 'D:NODE JSexpress-server.js'

at Module._resolveFilename (node:internal/modules/cjs/loader:1140:15)

at Module._load (node:internal/modules/cjs/loader:981:27)

at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:128:12)

at node:internal/main/run_main_module:28:49 {

code: 'MODULE_NOT_FOUND',

requireStack: []

}

Node.js v18.20.4

bro.. this error occurs, can you guide how to solve

@_hulk748
30 days ago

Thanks a lot for clear explanation sir🙏🙇‍♂

@francescagia2533
30 days ago

unfortunately it is not entirely in English 🙁

@sufiyanpatel6241
30 days ago

Amazing Teaching 👏

@khuramhanif7137
30 days ago

what do you mean by "tmy" Nonsense !!

@abhinavgupta1993
30 days ago

Hi Piyush, This side Abhinav.
I want to know about what extensions are you using in vc code for Node js and javascript.
I request you to share the list of extension which help write code in vs code i.e. suggestions, yellow symbol of js, green symbol before package.json etc.
Thank you 🙂 <3

@SahilSharma-cz1ox
30 days ago

i am facing module not found error
can anyone suggest
how can i solve it

@doctoronline461
30 days ago

Two youtubers I loved most piyush and hitesh sir.