Run an Angular application
Host an Angular SPA with a routing fallback, or an Angular SSR application running on Node.js.
An Angular application can be hosted in two ways. Pick the section that matches how your application is built:
| Type | What runs on the server | What you need |
|---|---|---|
| SPA (single-page application) | Nothing — the build is a set of static files. | A web.config with a rewrite rule that sends Angular routes to index.html. |
| SSR (server-side rendering) | A Node.js process that renders the pages. | A web.config that starts the Node.js server of the application. |
In both cases you build the application on your computer and upload the result into /wwwroot. Start by creating a website in the Control Panel — see Create your first website.
Angular SPA
The example uses the official Angular sample Tour of Heroes.
Download and build the sample
Download toh-pt6.zip and extract it into a folder named
toh. Open a command prompt and run:# change directory cd toh # install dependencies npm install # start local server ng serve # build production ng buildng serveruns the application locally so that you can try it;ng buildcreates the production build in thedistdirectory.Upload the build
Upload the entire content of the
dist\browser\directory into/wwwrooton your website, for example over FTP or SFTP.Upload web.config
Angular handles its routes in the browser, so an address such as
/heroesdoes not exist as a file on the server. Upload thisweb.configinto/wwwroot; it falls back toindex.htmlfor every address that is not an existing file or directory, and Angular then handles the route:<configuration> <system.webServer> <rewrite> <rules> <rule name="Angular Routes" stopProcessing="true"> <match url=".*" /> <conditions logicalGrouping="MatchAll"> <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" /> <add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" /> </conditions> <action type="Rewrite" url="./index.html" /> </rule> </rules> </rewrite> </system.webServer> </configuration>Open the website
Open the address of your website. You should see the Tour of Heroes application.
Note
Without the web.config the home page works, but opening or refreshing any other route directly returns 404.
Angular SSR
The example uses the public Angular 20 Example HttpClient application from github.com/ganatan/angular-httpclient.
Download and build the sample
Open a command prompt and run:
# download application from github git clone https://github.com/ganatan/angular-httpclient.git # change directory cd angular-httpclient # install dependencies npm install # start server npm start # build production npm run buildThe production build is created in the
dist\angular-starter\directory.Upload the build
Upload the entire content of the
dist\angular-starter\directory into/wwwrooton your website, for example over FTP or SFTP.Upload web.config
Upload this
web.configinto/wwwroot. It starts the Node.js server of the application and passes it the port to listen on:<configuration> <system.webServer> <handlers> <add name="httpPlatformHandler" path="*" verb="*" modules="httpPlatformHandler" resourceType="Unspecified" /> </handlers> <httpPlatform processPath="node" arguments=".\server\server.mjs" startupTimeLimit="20" stdoutLogEnabled="false" stdoutLogFile=".\logs\node"> <environmentVariables> <environmentVariable name="PORT" value="%HTTP_PLATFORM_PORT%" /> <environmentVariable name="NODE_ENV" value="production" /> </environmentVariables> </httpPlatform> </system.webServer> </configuration>Open the website
Open the address of your website. You should see the Angular 20 Example HttpClient application.
For your own application, replace angular-starter with the name of your project's output folder. /wwwroot is the website root, and web.config must be located directly in it.
Tip
If the project is on GitHub, Git deploy can build it on our server: Build Node.js SPA for a SPA and Node.js SSR app for SSR.
The SSR application does not start
Turn on the HttpPlatform debug log to see the output of the Node.js process. See Node.js debug logging (HttpPlatform).