How to log server 404 and 500 issues for NextJs applications in Sentry JS Project

const app = next({ dev: local });
const handler = routes.getRequestHandler(app);
const server = express();

      .listen(port, (err) => {
        if (err) throw err;
        console.log(`> Ready on http://localhost:${port}`);

Above is the current server setup for Next Js app in express, and not able to log 404 and 500 errors in sentry.
What else needed to be done to log the 404 and 500 error in Sentry JS project.

Current requirement - To log the Client and Server issue on same Sentry project