Next.js Discord

Discord Forum

Node production deployment without `next` CLI

Unanswered
West African Lion posted this in #help-forum
Open in Discord
Avatar
West African LionOP
Hello,

after running npm run build it is recommended to run npm start to run SSR server, running next start under-the-hood.

While this works great, I have a challenge with logging I need to overcome.

I need to track all console.log and console.error during SSR, and report it to another software.

To achieve this, I managed to use following approaches in other frameworks:
1. Add --require logging.js to node server/index.js command (when build output had Node script to run SSR server)
2. Write custom HTTP server with proper logging handling, and import framework's handler for SSR logic
If you want specific examples, feel free to ask, I just didn't want to promote specific frameworks

Sadly something like next start --require="logging.js" is not possible, as that flag only exists in node CLI command.

How could achieve such an injection of custom code when running Next.js SSR application using Node?

Are there some other tricks I could use? The main goal is not to require any webapp code changes, and even a default hello-world next.js app should work just fine.

1 Reply

Avatar
West African LionOP
Ah, found it! I totally missed it in docs in the first look.

Next-provided server docs: https://nextjs.org/docs/pages/building-your-application/deploying#nodejs-server

Custom Node server docs: https://nextjs.org/docs/pages/building-your-application/configuring/custom-server