const html = '<h1>Hello, World!</h1>'; const express = require('express'); const app = express(); app.get('*', (req, res) => { // That's all you need to do! If you pass a string to `res.send()`, // Express sets the response-type header to `text/html` res.send(html); }); const server = await app.listen(3000); // Example of using the server const axios = require('axios'); const res = await axios.get('http://localhost:3000'); res.headers['content-type']; // 'text/html; charset=utf-8' res.data; // '<h1>Hello, World!</h1>'
Preview:
downloadDownload PNG
downloadDownload JPEG
downloadDownload SVG
Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!
Click to optimize width for Twitter