Node JS

How to Reading files with Node.js

This is tutorial teach you how to reading files with Node.js.in the example we are not create the express server instead of that we created the http model   inside the http model has createServer function.easy way to reading the in node js implementing the method fs.readFile

server.js

const http = require("http");
const fs = require("fs");
http.createServer((req,res)=>
{
    fs.readFile("./index.html", (err,data)=>{
        if(err)
        {
            res.end("Page not found")
        }
        else
        {
            res.end(data)
        }
    })
}).listen(4000,()=>{

    console.log("Server Started");
})

File made as index.html

index.html

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <h1>Message 1</h1>
</body>
</html>

I have attached the video link below. which will do this tutorials step by step.

 

 

admin

Recent Posts

Touchable shop Pos system using Java

The Touchable Shop POS (Point of Sale) system is a sophisticated software solution developed using…

2 weeks ago

Build Your First Responsive Login Form Using HTML and CSS FlexBox

Creating a responsive login form is a crucial skill for any web developer. In this…

3 weeks ago

Build Crud API with Laravel 12

In this tutorial will teach  Laravel 12 CRUD API  by step. Laravel  10 CRUD Application …

3 weeks ago

laravel 12 image upload tutorial

In this lesson we talk about laravel 12 image uploading and display the image step…

4 weeks ago

Laravel 12 CRUD Application

In this tutorial will teach Laravel 12 CRUD Application step by step. Laravel  12 CRUD…

1 month ago

Conditional Statements in Python

Conditional statements in Python allow us to control the flow of execution based on conditions.…

2 months ago