Header Ads Widget

BCA Information

nodeslip6A


 var http = require('http');

var url = require('url');

var fs = require('fs');


http.createServer(function (req, res) {

  var q = url.parse(req.url, true);

  var filename = "slipno6.txt" + q.pathname;

  fs.readFile(filename, function(err, data) {

    if (err) {

      res.writeHead(404, {'Content-Type': 'text/html'});

       res.end("404 Error");

    } 

    res.writeHead(200, {'Content-Type': 'text/html'});

    res.write(data);

       res.end();

  });

}).listen(8080);





or by using Express module


slip6.js

const express=require('express')
const app=express()

app.use(express.static(_dirname+'/public'));

app.get('/',(req,res)=>{


res.sendFile(_dirname+"/index.html");
})

app.get("*",(req,res)=>  {
 res.sendFile(_dirname+ "/404.html")
})


app.listen(4000,()=>{
console.log("server is running on port 4000")
})




index.html

<!DOCTYPE html>
<html>
<head>
<title>form</title>
<style>

body{background-color:goldenrod;}
h1{text-align:center;
font-size:70px;
color:red;
background-color:green;
}

p{
color:blue;
text-align:center;
font-size:20px;
}

</style>

<body>
<marquee><h1>Bharatiya Jain sanghtans ASC College</h1></marquee>
<center><img src="image.gif" width="600"height="340"></center>

<h2>
Bharatiya jain Sanghtanas


arts Science and commerece college<br>
Bakori road,wagholi ,Pune-412207.<br>
</h2>
<a href=p2.html>click here for registration</a>
</h2>
</body>
</html>


404.html

<!DOCTYPE html>
<html>
<head>
<title>form</title>
<style>

body{background-color:rgb(248,247,174);}
.error-template{padding:40px 15px;text-align:center;}
.error-action{margin-top:15px;margin-bottom:15px;}
.error-action.btn{margin-right:10px;}
color:red;
background-color:green;
}

p{
color:blue;
text-align:center;
font-size:20px;
}

</style>

<body>
<div class="container">


 <div class="row">
 <div class="col-md-12">
  <div class="error-template">
   <h1>
    Oops!</h1>
<h2>
404 Not Found</h2>
<div class="error-details">
404,an error has occured,Requestedpage not found!
</div>

<div class="error-actions">
<a href="/" class="btn btn-primary btn-lg">
Go to Home Page</a>
</div>
</div>
</div>





</body>
</html>

Post a Comment

0 Comments

Popular Posts

Visual Basic 6.0 Program
Node js practical