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.

  1. 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 build
    

    ng serve runs the application locally so that you can try it; ng build creates the production build in the dist directory.

  2. Upload the build

    Upload the entire content of the dist\browser\ directory into /wwwroot on your website, for example over FTP or SFTP.

  3. Upload web.config

    Angular handles its routes in the browser, so an address such as /heroes does not exist as a file on the server. Upload this web.config into /wwwroot; it falls back to index.html for 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>
    
  4. 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.

  1. 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 build
    

    The production build is created in the dist\angular-starter\ directory.

  2. Upload the build

    Upload the entire content of the dist\angular-starter\ directory into /wwwroot on your website, for example over FTP or SFTP.

  3. Upload web.config

    Upload this web.config into /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>
    
  4. 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).

Still stuck? Our support team is happy to help.
Ask the community Open a support ticket