Skip to main content

What does the ng add @angular/ssr command do?

The command:

javascript
ng add @angular/ssr

automatically enables SSR (Server-Side Rendering) in an existing Angular project and configures Angular Universal.


What exactly this command does:

  1. Installs the required packages
  • @angular/ssr
  • @angular/platform-server
  • and related dependencies
  1. Adds a server build
  • creates the files for rendering on the server (Node.js)
  • adds main.server.ts
  1. Updates the Angular configuration
  • extends angular.json with SSR tasks (a server and ssr build)
  1. Changes AppModule
  • adds Universal support
  • registers the required providers
  1. Adds commands to npm-scripts, for example:
javascript
npm run build:ssr npm run serve:ssr

so you can build and run the SSR version of the application


What this gives you:

After ng add @angular/ssr your Angular project can:

  • render pages on the server
  • serve finished HTML before JS loads
  • improve SEO, first-paint speed, and previews on social media

Conclusion:

The ng add @angular/ssr command is a quick way to automatically enable SSR and Angular Universal in a project without manual setup.

Short Answer

Interview ready
Premium

A concise answer to help you respond confidently on this topic during an interview.