// Step 1: Import required modules
const express = require('express');
const path = require('path');
// Step 2: Create an Express application
const app = express();
// Step 3: Define the folder containing images
const imagePath = path.join(__dirname, 'images');
// Step 4: Set up a route to handle image requests
app.get('/images/:imageName', (req, res) => {
// Step 5: Get the requested image name from the URL parameters
const imageName = req.params.imageName;
// Step 6: Construct the path to the requested image
const imagePath = path.join(__dirname, 'images', imageName);
// Step 7: Send the image file as a response
res.sendFile(imagePath);
});
// Step 8: Set up the server to listen on a specific port (e.g., 3000)
const PORT = 3000;
app.listen(PORT, () => {
console.log(`Server is running on port ${PORT}`);
});