Express Static Files

Aim

To serve static files such as HTML, CSS and images using Express.js.

What are Static Files?

Static files are files that are sent directly to the browser without changing their content.

Example

const express = require("express");

const app = express();

app.use(express.static("public"));

app.listen(3002, () => {
    console.log("Server running on port 3002");
});
    

Output

Static files are successfully served using Express.js.