Send Html File Express

send html file express
res.sendFile(path.join(__dirname + '/index.html'));
express send html file
app.get('/test', function(req, res) {
res.sendFile('test.html', {root: __dirname })
});
express return html file
//res.sendFile(path [, options] [, fn])
app.get('/test', function(req, res) {
res.sendFile('test.html')
});
express send html from string
// Express.JS: Send HTML from string
res.send(`
<h1>Welcome</h1>
<h2>Scroll to learn more</h2>
`);

Leave a Comment