Thursday, 3 October 2019

Show Webpage

Hi All,

User the following steps

1. Create Server.js

var http = require('http');
var url = require('url');
var fs = require('fs');

http.createServer(function (reqres) {
  var q = url.parse(req.urltrue);
  var filename = "." + q.pathname;
  fs.readFile(filenamefunction(errdata) {
    if (err) {
      res.writeHead(404, {'Content-Type': 'text/html'});
      return res.end("404 Not Found");
    } 
    res.writeHead(200, {'Content-Type': 'text/html'});
    res.write(data);
    return res.end();
  });
}).listen(8080);

2. Create webpage

<!DOCTYPE html>
<html>
<body>
<h1>Winter</h1>
<p>I love the Rose!</p>
</body>
</html>

3: run using

localhost:8080/hupwriter.html

No comments:

Post a Comment