Answers for "show html file on nodejs code"

1

show html file on nodejs code

let http = require('http');
let fs = require('fs');
 
let handleRequest = (request, response) => {
    response.writeHead(200, {
        'Content-Type': 'text/html'
    });
    fs.readFile('./index.html', null, function (error, data) {
        if (error) {
            response.writeHead(404);
            respone.write('Whoops! File not found!');
        } else {
            response.write(data);
        }
        response.end();
    });
};
 
http.createServer(handleRequest).listen(8000);
Posted by: Guest on September-02-2020

Code answers related to "Javascript"

Browse Popular Code Answers by Language