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!
node hello.js likhne pr console.log me jo word likhe h nhi aa rhe hai
Thankyou Sir
nicely explained.
very helpful video bro
crystal clear 😍
awesome
Video useful
Brother thank you for this playlist
BHAI YEH EMPTY FOLDER BANAYA KAHA HAI ?? git pe??
thankyou bhaiya
This is perfect for learning NodeJs and understanding deeply the concepts.
Awsome brother!! subscribed your channel
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
Thanks a lot for clear explanation sir🙏🙇♂
unfortunately it is not entirely in English 🙁
Amazing Teaching 👏
what do you mean by "tmy" Nonsense !!
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
i am facing module not found error
can anyone suggest
how can i solve it
Two youtubers I loved most piyush and hitesh sir.