// Step 1: Import required modules
const express = require('express');
const app = express();
// Step 2: Define a dynamic route with a parameter
app.get('/user/:userId', (req, res) => {
const userId = req.params.userId;
res.send(`User ID: ${userId}`);
});
// Step 3: Define an error handler middleware
app.use((err, req, res, next) => {
console.error(err.stack);
res.status(500).send('Something went wrong!');
});
// Step 4: Start the server on port 3000
const PORT = 3000;
app.listen(PORT, () => {
console.log(`Server is running on port ${PORT}`);
});