how express serve public folder

const express = require('express');
const path = require('path');

const app = express();
const port = 3000;

// Step 1: Define the path to the public folder
const publicFolderPath = path.join(__dirname, 'public');

// Step 2: Use express.static middleware to serve files from the public folder
app.use(express.static(publicFolderPath));

// Step 3: Set up a route handler for the root URL to serve the index.html file
app.get('/', (req, res) => {
  res.sendFile(path.join(publicFolderPath, 'index.html'));
});

// Step 4: Start the server
app.listen(port, () => {
  console.log(`Server is running on port ${port}`);
});