![Deno 2.2 Improves Dependency Management and Expands Node.js Compatibility](https://cdn.sanity.io/images/cgdhsj6q/production/97774ea8c88cc8f4bed2766c31994ebc38116948-1664x1366.png?w=400&fit=max&auto=format)
Security News
Deno 2.2 Improves Dependency Management and Expands Node.js Compatibility
Deno 2.2 enhances Node.js compatibility, improves dependency management, adds OpenTelemetry support, and expands linting and task automation for developers.
@nguniversal/express-engine
Advanced tools
This is an Express Engine for running Angular Apps on the server for server side rendering.
npm install @nguniversal/express-engine --save
To use it, set the engine and then route requests to it
import express from 'express';
import { ngExpressEngine } from '@nguniversal/express-engine';
const app = express();
// Set the engine
app.engine(
'html',
ngExpressEngine({
bootstrap: ServerAppModule, // Give it a module to bootstrap
}),
);
app.set('view engine', 'html');
app.get('/**/*', (req: Request, res: Response) => {
res.render('../dist/index', {
req,
res,
});
});
It is possible to override the default URL and document fetched when the rendering engine
is called. To do so, simply pass in a url
and/or document
string to the renderer as follows:
app.get('/**/*', (req: Request, res: Response) => {
let url = 'http://someurl.com';
let doc = '<html><head><title>New doc</title></head></html>';
res.render('../dist/index', {
req,
res,
url,
document: doc,
});
});
Extra Providers can be provided either on engine setup
app.engine(
'html',
ngExpressEngine({
bootstrap: ServerAppModule,
providers: [ServerService],
}),
);
The Bootstrap module as well as more providers can be passed on request
app.get('/**/*', (req: Request, res: Response) => {
res.render('../dist/index', {
req,
res,
bootstrap: OtherServerAppModule,
providers: [OtherServerService],
});
});
The Request and Response objects are injected into the app via injection tokens. You can access them by @Inject
import { Request } from 'express';
import { REQUEST } from '@nguniversal/express-engine/tokens';
@Injectable()
export class RequestService {
constructor(@Inject(REQUEST) private request: Request) {}
}
If your app runs on the client side too, you will have to provide your own versions of these in the client app.
You can also use a custom callback to better handle your errors
app.get('/**/*', (req: Request, res: Response) => {
res.render(
'../dist/index',
{
req,
res,
},
(err: Error, html: string) => {
res.status(html ? 200 : 500).send(html || err.message);
},
);
});
FAQs
Express Engine for running Server Angular Apps
The npm package @nguniversal/express-engine receives a total of 54,588 weekly downloads. As such, @nguniversal/express-engine popularity was classified as popular.
We found that @nguniversal/express-engine demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 2 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Deno 2.2 enhances Node.js compatibility, improves dependency management, adds OpenTelemetry support, and expands linting and task automation for developers.
Security News
React's CRA deprecation announcement sparked community criticism over framework recommendations, leading to quick updates acknowledging build tools like Vite as valid alternatives.
Security News
Ransomware payment rates hit an all-time low in 2024 as law enforcement crackdowns, stronger defenses, and shifting policies make attacks riskier and less profitable.