Working with Express.js
If using express, hot server hot module reloading may not work after these steps
Express has its own route stack, so reloading require cache will not be enough to reload the routes inside express.
Add global callback in express
For hot module reloading with Express and Next.js, setting up a global callback to clear the Express route cache is required. This allows route updates to be recognized without server restarts.
server/express.js
Trigger callback in revalidation
add a global callback in _document.js to clear the Express route cache during revalidation, allowing updated routes to be served without server restarts.
pages/_document.js