Passing HTML to res.send

Now that we have a very basic example, we want to step things up a notch. Inside Atom, we can actually provide some HTML right inside of send by wrapping our Hello Express! message in an h1 tag. Later in this section, we'll be setting up a static website that has HTML files that get served up. We'll also look at templating to create dynamic web pages. But for now, we can actually just pass in some HTML to res.send:

app.get('/', (req, res) => {  res.send('<h1>Hello Express!</h1>');});app.listen(3000);

We'll save the server file, which should restart things in the browser. When we give the browser a refresh, we get Hello Express! printing to the screen:

This time though, we have it in an h1 tag, which means it's formatted ...

Get Learning Node.js Development now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.