Express Render HTML

Express Render HTML

Express makes it easy to render plain HTML, either from a JavaScript string or from a file. Given an HTML string, all you need to do is call res.send(), Express takes care of setting the content-type header for you

Given some plain HTML, how do you render it using Express? Here's what you need to know.

Express makes it easy to render plain HTML, either from a JavaScript string or from a file. Given an HTML string, all you need to do is call res.send(), Express takes care of setting the content-type header for you:

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>'

express html node javascript web-development

Bootstrap 5 Complete Course with Examples

Bootstrap 5 Tutorial - Bootstrap 5 Crash Course for Beginners

Nest.JS Tutorial for Beginners

Hello Vue 3: A First Look at Vue 3 and the Composition API

Building a simple Applications with Vue 3

Deno Crash Course: Explore Deno and Create a full REST API with Deno

How to Build a Real-time Chat App with Deno and WebSockets

Convert HTML to Markdown Online

HTML entity encoder decoder Online

Node.js Express PDF to HTML Files Converter Web Application Online in Javascript 2020

Node.js Express PDF to HTML Files Converter Web Application Online in Javascript 2020

How to SETUP a WEB SERVER in Node.js, Express, JavaScript & HTML

Hey guys and gurls. I'll be showing you how to create a simple server using express in node.js. This is a super simple concept I believe everyone who's down

Node.js Express HTML IFrame Tag Generator in JavaScript

Node.js Express HTML IFrame Tag Generator in Javascript Full Project For Beginners 2020

Node.js Express Compress Minify Raw HTML Code Online Compressor Tool Made in JavaScript Project 2020

Node.js Express Compress Minify Raw HTML Code Online Compressor Tool Made in Javascript Project 2020 Free Live Demo of HTML Compressor Tool Here: https://fre...

Hire Node.JS Developers | Skenix Infotech

We are providing robust Node.JS Development Services with expert Node.js Developers. Get affordable Node.JS Web Development services from Skenix Infotech.