Skip to content Skip to sidebar Skip to footer

How To Send Html As A Response In Rest?

I have created an API in Nodejs. I have tried creating a call which returns HTML to display a site in the browser. My Call looks like this: router.get('/displayHTML', checkAccessTo

Solution 1:

Check the fs_library: https://nodejs.org/docs/v0.3.1/api/fs.html

var http = require('http'),
lib = require('fs');
lib.readFile('./page.html', function (err, html) {
    if (err) {
        throw err; 
    }       
    http.createServer(function(request, response) {  
        response.writeHeader(200, {"Content-Type": "text/html"});  
        response.write(html);  
        response.end();  
    }).listen(8000);
});

Post a Comment for "How To Send Html As A Response In Rest?"