express send raw html

To send raw HTML using Express, you can follow these steps:

  1. Import the necessary modules: const express = require('express'); const app = express();

  2. Create a route handler for the desired endpoint: `` app.get('/html', (req, res) => { // Your HTML code here const html =Raw HTML Example

    Hello, World!

    `;

    res.send(html); }); ```

  3. Start the server: app.listen(3000, () => { console.log('Server running on port 3000'); });

Explanation:

  1. In the first step, we import the Express module and create an instance of the app.

  2. Next, we define a route handler using the app.get() method. This handler listens for GET requests to the /html endpoint. Inside the handler, we create a variable html that stores the raw HTML code you want to send as a response.

  3. Finally, we start the server by calling the app.listen() method. This tells Express to listen for incoming requests on port 3000. Once the server is running, it logs a message to the console.

By following these steps, you can send raw HTML as a response using Express. Remember to customize the HTML code inside the html variable to suit your specific needs.