What does the ng add @angular/ssr command do?
The command:
javascript
ng add @angular/ssrautomatically enables SSR (Server-Side Rendering) in an existing Angular project and configures Angular Universal.
What exactly this command does:
- Installs the required packages
@angular/ssr@angular/platform-server- and related dependencies
- Adds a server build
- creates the files for rendering on the server (Node.js)
- adds
main.server.ts
- Updates the Angular configuration
- extends
angular.jsonwith SSR tasks (aserverandssrbuild)
- Changes AppModule
- adds Universal support
- registers the required providers
- Adds commands to npm-scripts, for example:
javascript
npm run build:ssr
npm run serve:ssrso 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 readyPremium
A concise answer to help you respond confidently on this topic during an interview.