cd ./dist/angular-ssr/server
node server.mjs
8. Stop the local server to release in-use files, archive the dist folder and its sub-items to .zip file
If you use other NodeJS packages in your project, you will also need to package the entire node_modules folder and upload it to the server
10. Unzip the .zip file to the target site path, i.e. site3
11. Create an app.js file under site3 folder and set its content as:
import("./dist/angular-ssr/server/server.mjs");
13. Change the content of site3/web.config file to
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.webServer>
<handlers>
<add name="iisnode" path="app.js" verb="*" modules="iisnode" />
</handlers>
<rewrite>
<rules>
<rule name="DynamicContent">
<match url="/*" />
<action type="Rewrite" url="app.js"/>
</rule>
</rules>
</rewrite>
</system.webServer>
</configuration>
The final folder structure should be like:
site3/
|-- dist/
|-- angular-ssr/
|-- browser/
...
|-- server/
|-- server.mjs
...
...
|-- app.js
|-- web.config
14. Access your site URL to check the application
Troubleshooting
Case 1: In Angular version 19, the <project-name>/src/server.ts
file has been optimized and now includes a check to determine if this module is the main entry point. Despite following the previous steps, you might still encounter an HTTP 500 error with your Angular Universal app.
Solution: Modify your server.ts
file and add a new condition to handle scenarios when the application is hosted on a production server with iisnode. Refer to the highlighted section in the code below. Afterward, follow the steps above to build your app and re-upload the files to your account.
/**
* Start the server if this module is the main entry point.
* The server listens on the port defined by the `PORT` environment variable, or defaults to 4000.
*/
if (isMainModule(import.meta.url) || process.env["APP_POOL_ID"]?.toLowerCase() === "iisnode") {
const port = process.env['PORT'] || 4000;
app.listen(port, () => {
console.log(`Node Express server listening on http://localhost:${port}`);
});
}