# ng-universal **Repository Path**: mirrors_un33k/ng-universal ## Basic Information - **Project Name**: ng-universal - **Description**: Angular Universal module for Nest framework (node.js) 🌷 - **Primary Language**: Unknown - **License**: MIT - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2020-09-26 - **Last Updated**: 2026-11-09 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README

Nest Logo

[travis-image]: https://api.travis-ci.org/nestjs/nest.svg?branch=master [travis-url]: https://travis-ci.org/nestjs/nest [linux-image]: https://img.shields.io/travis/nestjs/nest/master.svg?label=linux [linux-url]: https://travis-ci.org/nestjs/nest

A progressive Node.js framework for building efficient and scalable server-side applications, heavily inspired by Angular.

NPM Version Package License NPM Downloads Travis Linux Coverage Discord Backers on Open Collective Sponsors on Open Collective

## Description Angular [Universal](https://github.com/angular/universal) module for [Nest](https://github.com/nestjs/nest). ## Installation Using the Angular CLI: ```bash $ ng add @nestjs/ng-universal ``` Or manually: ```bash $ npm i --save @nestjs/ng-universal ``` ## Example See full example [here](https://github.com/kamilmysliwiec/universal-nest). ## Usage Simply import `AngularUniversalModule` in your Nest application. ```typescript import { Module } from '@nestjs/common'; import { join } from 'path'; import { AngularUniversalModule } from '@nestjs/ng-universal'; @Module({ imports: [ AngularUniversalModule.forRoot({ viewsPath: join(process.cwd(), 'dist/browser'), bundle: require('./../dist/server/main.js'), }), ], }) export class ApplicationModule {} ``` ## API Spec The `forRoot()` method takes an options object with a few useful properties. | Property | Type | Description | | ------------- | ------------- | ----- | | `viewsPath` | string | The directory where the module should look for client bundle (Angular app) | | `bundle` | Object | Bundle file (webpack output with `AppServerModuleNgFactory`) | | `templatePath` | string? | Path to index file (default: `{viewsPaths}/index.html`) | | `rootStaticPath` | string? | Static files root directory (default: `*.*`) | | `renderPath` | string? | Path to render Angular app (default: `*`) | | `extraProviders` | StaticProvider[]? | The platform level providers for the current render request | ## Request and Response Providers This tool uses `@nguniversal/express-engine` and will properly provide access to the Express Request and Response objects in you Angular components. This is useful for things like setting the response code to 404 when your Angular router can't find a page (i.e. `path: '**'` in routing): ```ts import { Response } from 'express'; import { Component, Inject, Optional, PLATFORM_ID } from '@angular/core'; import { isPlatformServer } from '@angular/common'; import { RESPONSE } from '@nguniversal/express-engine/tokens'; @Component({ selector: 'my-not-found', templateUrl: './not-found.component.html', styleUrls: ['./not-found.component.scss'], }) export class NotFoundComponent { constructor( @Inject(PLATFORM_ID) private readonly platformId: any, @Optional() @Inject(RESPONSE) res: Response, ) { // `res` is the express response, only available on the server if (isPlatformServer(this.platformId)) { res.status(404); } } } ``` ## Support Nest is an MIT-licensed open source project. It can grow thanks to the sponsors and support by the amazing backers. If you'd like to join them, please [read more here](https://docs.nestjs.com/support). ## Stay in touch * Author - [Kamil Myśliwiec](https://kamilmysliwiec.com) * Website - [https://nestjs.com](https://nestjs.com/) * Twitter - [@nestframework](https://twitter.com/nestframework) ## License Nest is [MIT licensed](LICENSE).