In this article we will learn about some of the frequently asked TypeScript programming questions in technical like “how to convert a normal app to a Angular Universal” Code Answer. When creating scripts and web applications, error handling is an important part. If your code lacks error checking code, your program may look very unprofessional and you may be open to security risks. Error or stack handling on typescript was simple and easy. An error message with filename, line number and a message describing the error is sent to the browser. This tutorial contains some of the most common error checking methods in Typescript. Below are some solution about “how to convert a normal app to a Angular Universal” Code Answer.
how to convert a normal app to a Angular Universal
xxxxxxxxxx
1
require('zone.js/dist/zone-node');
2
3
require('reflect-metadata');
4
5
const express = require('express');
6
7
const fs = require('fs');
8
9
const { platformServer, renderModuleFactory } = require('@angular/platform-server');
10
11
const { ngExpressEngine } = require('@nguniversal/express-engine');
12
13
// Import the AOT compiled factory for your AppServerModule.
14
15
// This import will change with the hash of your built server bundle.
16
17
const { AppServerModuleNgFactory } = require(`./dist-server/main.bundle`);
18
19
const app = express();
20
21
const port = 8000;
22
23
const baseUrl = `http://localhost:${port}`;
24
25
// Set the engine
26
27
app.engine('html', ngExpressEngine({
28
29
bootstrap: AppServerModuleNgFactory
30
31
}));
32
33
app.set('view engine', 'html');
34
35
app.set('views', 'dist');
36
37
app.use('/', express.static('dist', {index: false}));
38
39
app.get('*', (req, res) => {
40
41
res.render('../dist/index.html', {
42
43
req,
44
45
res
46
47
});
48
49
});
50
51
app.listen(port, () => {
52
53
console.log(`Listening at ${baseUrl}`);
54
55
});
56
57
58