8 Replies
Hi @Zhaolin Lau. I'm kapa.ai, your friendly support bot. I will try to answer your question by searching through the knowledge base. :wave:
----------------------
To host a Nuxt 4 SSR (Server-Side Rendered) application with PM2, follow these steps:
1. Build your Nuxt app for production:
2. Create a PM2 ecosystem config file (e.g.,
ecosystem.config.cjs):
3. Start your app with PM2:
This will run your Nuxt SSR server in cluster mode, utilizing all available CPU cores for better performance. The entry point is ./.output/server/index.mjs, which is generated by the Nuxt build process. You can adjust the port and other settings as needed.
4. (Optional) Use environment variables to set the port or host:
- NITRO_PORT or PORT (defaults to 3000)
- NITRO_HOST or HOST (defaults to '0.0.0.0')
Example:
Note: It's recommended to run your Nuxt server behind a reverse proxy (like Nginx or Apache) in production for SSL termination and better security.
For more details, see the official documentation: Nuxt 4 Deployment with PM2
----------------------
Note: you can ask me a follow up question by @ mentioning me again :speech_balloon:
----------------------<@520675622830342144> Kapa.ai is still learning and improving, please let me know how I did by reacting below.
@kapa.ai @Zhaolin Lau if i push a commit and want to deploy, will i need to restart the pm2 or something?
Let me check the knowledge base for you again. One moment! :books:
----------------------
Yes, after you push a new commit and deploy your updated Nuxt 4 SSR application, you will need to restart your PM2 process to run the new build. This is because PM2 will continue running the old server instance until you explicitly restart it to pick up the changes in your code and the new build output. The typical workflow is:
1. Pull your latest changes.
2. Run
npx nuxt build to generate the new production build.
3. Restart PM2 to use the updated build, for example:
This ensures your live application is serving the latest code and assets. This process is standard for Nuxt SSR deployments with PM2, as described in the official documentation Nuxt 4 Deployment with PM2.
----------------------
Note: you can ask me a follow up question by @ mentioning me again :speech_balloon:
----------------------<@520675622830342144> Kapa.ai is still learning and improving, please let me know how I did by reacting below.
@kapa.ai if i restart, will it the client side down?
Let me check the knowledge base for you again. One moment! :books:
----------------------
When you restart your Nuxt SSR server with PM2, there will be a brief downtime for your application, as the server process is stopped and then started again. During this short period, both server-side and client-side rendering will be unavailable to users.
However, if you use PM2's cluster mode (as shown in the recommended
ecosystem.config.cjs), PM2 will restart your application processes one by one (zero-downtime reload), which helps minimize downtime. Still, there may be a very brief moment when a user request could fail if all processes are being restarted simultaneously, but in most cases, the downtime is negligible.
This behavior is standard for Node.js applications managed by PM2 and is not specific to Nuxt. The official Nuxt documentation describes using PM2 in cluster mode for better performance and reliability, but does not explicitly guarantee zero downtime during restarts Nuxt 4 Deployment with PM2.
If you need true zero-downtime deployments, you should consider using a load balancer with multiple servers or advanced deployment strategies.
----------------------
Note: you can ask me a follow up question by @ mentioning me again :speech_balloon:
----------------------<@520675622830342144> Kapa.ai is still learning and improving, please let me know how I did by reacting below.