Skip to content
  • SiteMap
  • Our Services
  • Frequently Asked Questions (FAQ)
  • Support
  • About Us

UpdateGadh

Update Your Skills.

  • Home
  • Projects
    •  Blockchain projects
    • Python Project
    • Data Science
    •  Ai projects
    • Machine Learning
    • PHP Project
    • React Projects
    • Java Project
    • SpringBoot
    • JSP Projects
    • Java Script Projects
    • Code Snippet
    • Free Projects
  • Tutorials
    • Ai
    • Machine Learning
    • Advance Python
    • Advance SQL
    • DBMS Tutorial
    • Data Analyst
    • Deep Learning Tutorial
    • Data Science
    • Nodejs Tutorial
  • Blog
  • Contact us
  • Toggle search form
Node.js First Example

Nodejs First Example

Posted on September 15, 2025September 15, 2025 By Rishabh saini No Comments on Nodejs First Example

Nodejs First Example

Node.js applications can be of two main types: console-based and web-based. Let’s walk through simple examples of both to help you get started.

Introduction to Applied AI:-Click Here

Node.js Console-Based Example

File: console_example1.js

console.log('Hello UpdateGadh');

How to Run It:

  1. Open the Node.js command prompt.
  2. Navigate to the directory where you saved the file.
  3. Run the following command:

node console_example1.js

Explanation:
The console.log() function simply prints the message to the console. This is the most basic way to test that Node.js is installed and working correctly.

Node.js Web-Based Example

A simple Node.js web application generally includes three steps:

  1. Import required modules – Use the require directive to load the http module and assign it to a variable. var http = require("http");
  2. Create a server – Establish a server that listens for client requests, similar to an Apache HTTP server.
  3. Read requests and return responses – The server will handle incoming HTTP requests and send back a response.

Data Science Tutorial:-Click Here

Complete Example

File: main.js

var http = require("http");

http.createServer(function (request, response) {  
   // Send the HTTP header   
   // HTTP Status: 200 : OK  
   // Content Type: text/plain  
   response.writeHead(200, {'Content-Type': 'text/plain'});  

   // Send the response body  
   response.end('Hello World\n');  
}).listen(8081);  

// Console will print this message  
console.log('Server running at http://127.0.0.1:8081/');

Explanation of Steps

  1. Import Required Module
    Load the http module using the require directive and store it in a variable.
  2. Create Server
    Use http.createServer() to create a server instance. Then, use the listen() method to bind it to port 8081. The function passed as an argument handles requests (request) and sends responses (response).
  3. Combine Steps
    Save the combined code in a file named main.js.

Running the Server

  1. Open the Node.js command prompt.
  2. Navigate to the location where you saved main.js. For example, if it’s saved on the desktop: cd desktop
  3. Start the server with: node main.js

Once the server starts, the console will display:

Download New Real Time Projects :-Click here

Server running at http://127.0.0.1:8081/

Test Your Server

Open a browser and visit:

http://127.0.0.1:8081/

You should see the output:

Hello World

If you make changes to main.js, restart the server by running node main.js again.

Machine Learning Tutorial:-Click Here

Complete Advance AI topics:- CLICK HERE
Deep Learning Tutorial:– Click Here

Conclusion
This was your very first step into building applications with Node.js — starting from a simple console example to a basic web server. As you move forward, you can expand these concepts into more complex and powerful applications.


how to run node js in terminal
sample node-js application github
node js download
node js run command
node js hello world example
how to run node js in visual studio code terminal
express js
node js tutorial
node js first example w3schools
node js first example github
node js first example for beginners
node js first example in javascript
node js first example geeksforgeeks

    Post Views: 247
    Node.js Tutorial Tags:build first nodejs web application server, creating your first app with node.js, express nodejs, expressjs nodejs, first example, first node application, first node js application, learn nodejs, node js application example, node js web server example, node.js - tutorial - first application, node.js first application, nodejs, nodejs begineers, nodejs beginners, nodejs first program, nodejs for beginners, nodejs training, nodejs tutorial, nodejs tutorials for beginners, your first node.js web server

    Post navigation

    Previous Post: Best Employee Leave Management System Using PHP & MYSQL
    Next Post: Best Bookstore Management System Using PHP & MySQL

    More Related Articles

    Node.js DNS module Node.js DNS module Node.js Tutorial
    Node.js Child Process Node.js Child Process Node.js Tutorial
    Node.js Crypto Node.js Crypto Node.js Tutorial

    Leave a Reply Cancel reply

    Your email address will not be published. Required fields are marked *

    You may also like

    1. Install Nodejs on Windows
    2. Node.js Child Process
    3. Node.js Assertion Testing
    4. Node.js Events
    5. Node.js MySQL Delete Records
    6. Node.js Create Connection with MongoDB

    Most Viewed Posts

    1. Top Large Language Models in 2025
    2. Online Shopping System using PHP, MySQL with Free Source Code
    3. login form in php and mysql , Step-by-Step with Free Source Code
    4. Flipkart Clone using PHP And MYSQL Free Source Code
    5. News Portal Project in PHP and MySql Free Source Code
    6. User Login & Registration System Using PHP and MySQL Free Code
    7. Top 10 Final Year Project Ideas in Python
    8. Blog Site In PHP And MYSQL With Source Code || Best Project
    9. Online Bike Rental Management System Using PHP and MySQL
    10. E learning Website in php with Free source code
    • AI
    • ASP.NET
    • Blockchain
    • ChatCPT
    • code Snippets
    • Collage Projects
    • Data Science Project
    • Data Science Tutorial
    • DBMS Tutorial
    • Deep Learning Tutorial
    • Final Year Projects
    • Free Projects
    • How to
    • html
    • Interview Question
    • Java Notes
    • Java Project
    • Java Script Notes
    • JAVASCRIPT
    • Javascript Project
    • JSP JAVA(J2EE)
    • Machine Learning Project
    • Machine Learning Tutorial
    • MySQL Tutorial
    • Node.js Tutorial
    • PHP Project
    • Portfolio
    • Python
    • Python Interview Question
    • Python Projects
    • PythonFreeProject
    • React Free Project
    • React Projects
    • Spring boot
    • SQL Tutorial
    • TOP 10
    • Uncategorized
    • Real-Time Medical Queue & Appointment System with Django
    • Online Examination System in PHP with Source Code
    • AI Chatbot for College and Hospital
    • Job Portal Web Application in PHP MySQL
    • Online Tutorial Portal Site in PHP MySQL — Full Project with Source Code

    Most Viewed Posts

    • Top Large Language Models in 2025 (8,616)
    • Online Shopping System using PHP, MySQL with Free Source Code (5,225)
    • login form in php and mysql , Step-by-Step with Free Source Code (4,875)

    Copyright © 2026 UpdateGadh.

    Powered by PressBook Green WordPress theme