Address
Darbhanga, Bihar 846004
Server-Side Rendering the Angular application has the following advantages:
To implement server side rendering in Angular application. Angular Universal package is used with the angular application.
From your app directory open a terminal and run the following command:
ng add @nguniversal/express-engine --clientProject YourProjectName
This command will install the required packages and it will add and update all required files to implement server-side rendering in angular application.
CREATE src/main.server.ts
CREATE src/app/app.server.module.ts
CREATE src/tsconfig.server.json
CREATE server.ts
UPDATE package.json
UPDATE angular.json
UPDATE src/main.ts
UPDATE src/app/app.module.ts
UPDATE tsconfig.json
run the following commands:
npm run build:ssr
npm run serve:ssr
This will serve the angular application with server-side rendered pages on http://localhost:4000 address
npm run build:ssr : This command compiles and create dist folder and in that folder there were 2 folders /browser and /server, normal build and server build.
dist
-browser
-server
npm run serve:ssr : This command serve /server folder only, but when any request is made from browser, it serve template and other static files from /browser folder.
Since a Universal application runs on the server and not in a browser, there are a few things you need to watch out for in your application code: