set 404 handling via express in node

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

// Define a middleware function for handling 404 errors
function handle404(req, res, next) {
  res.status(404).send('Not Found');
}

// Set the 404 handler middleware
app.use(handle404);

// Start the Express server
const PORT = 3000;
app.listen(PORT, () => {
  console.log(`Server is running on port ${PORT}`);
});