Skip to content

Angular SSR does not work OOB with PM2 #31081

Closed

Description

@hheexx

Which @angular/* package(s) are the source of the bug?

platform-server

Is this a regression?

Yes

Description

New angular server template does not work out of the box with most popular process manager PM2.
Unitech/pm2#5921
https://stackoverflow.com/questions/79214195/is-angular-19-0-incompatible-with-pm2

I guess that should be fixed.

Also there is no any documentation about running SSR in prod....

Please provide a link to a minimal reproduction of the bug

No response

Please provide the exception or error you saw


Please provide the environment you discovered this bug in (run ng version)


Anything else?

No response

Activity

  1. transferred this issue fromangular/angularon Aug 29, 2025
  2. alan-agius4 commented on Sep 1, 2025

    @alan-agius4
    Collaborator

    Feel free to modify the provided server.ts file to suit your specific server configuration, as it's just a basic starting point.

  3. added 2 commits that reference this issue on Sep 29, 2025
    b5d620e
    6d39c65
  4. PowerKiKi commented on Sep 29, 2025

    @PowerKiKi
    Contributor

    This tripped me too. I would expected the most popular process manager in node would be supported out of the box. I ended up with this:

      * Start the server if this module is the main entry point.
      * The server listens on the port defined by the `PORT` environment variable, or defaults to 4000.
      */
    -if (isMainModule(import.meta.url)) {
    +if (isMainModule(import.meta.url) || process.env.pm_id) {
         const port = process.env.PORT || 9003;
         app.listen(port, error => {
             if (error) {
  5. added 2 commits that reference this issue on Sep 29, 2025
    8ac5156
    c94bf7f
  6. hheexx commented on Oct 3, 2025

    @hheexx
    Author

    @alan-agius4 thanks!
    Any chance for cluster mode support?
    Currently it's not that easy to scale the app.

  7. alan-agius4 commented on Oct 3, 2025

    @alan-agius4
    Collaborator

    That a good idea, please feel free to open a feature request. Using cluster mode directly would certainly make it easier for developers to leverage multi-core CPUs for Angular SSR and would be a valuable feature request. However, it's crucial to understand that scaling isn't just a Node.js issue; it requires proper deployment infrastructure. Even with cluster support, running public traffic directly to the Node.js layer is not recommended.

    For robust scaling, one must use a Reverse Proxy/Load Balancer (like Nginx or a Cloud Load Balancer) in front of multiple Node.js SSR instances. This proxy is vital as it not only distributes the load but also offloads critical work serving static assets and handling SSL and allows you to implement aggressive caching at the edge/CDN layer.

  8. hheexx commented on Oct 4, 2025

    @hheexx
    Author

    @alan-agius4 Ok, here it is #31387
    Yea we use nginx anyway but cluster support would make configuration easier on nginx and pm2 sides.

  9. angular-automatic-lock-bot commented on Nov 4, 2025

    @angular-automatic-lock-bot

    This issue has been automatically locked due to inactivity.
    Please file a new issue if you are encountering a similar or related problem.

    Read more about our automatic conversation locking policy.

    This action has been performed automatically by a bot.

  10. locked and limited conversation to collaborators on Nov 4, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions