Skip to content
Docs Try Aspire

Polyglot AppHost

Preview feature

Aspire’s polyglot support allows you to write AppHosts in TypeScript instead of C#. This enables teams to use TypeScript while still benefiting from Aspire’s orchestration capabilities, including access to 40+ hosting integrations (Redis, PostgreSQL, Azure services, and more).

When you create a polyglot AppHost:

  1. The Aspire CLI scaffolds a TypeScript AppHost project
  2. A .NET AppHost Server runs in the background, handling orchestration
  3. Your code communicates with the server via JSON-RPC over Unix sockets (or named pipes on Windows)
  4. The server manages containers, service discovery, and the Aspire Dashboard
flowchart LR
    subgraph YourCode["Your Code"]
        TS["TypeScript AppHost"]
    end

    subgraph Server[".NET AppHost Server"]
        RPC["JSON-RPC"]
        ORCH["Orchestration"]
        SD["Service Discovery"]
    end

    subgraph Resources["Managed Resources"]
        DASH["Aspire Dashboard"]
        CONT["Containers"]
        INT["140+ Integrations"]
    end

    TS --> RPC
    RPC --> ORCH
    ORCH --> SD
    SD --> DASH & CONT & INT

This architecture gives you access to the full power of Aspire’s orchestration while writing code in TypeScript.

Before creating a polyglot AppHost, ensure you have the following installed:

RequirementVersionNotes
.NET SDK10.0+Required for the AppHost server
Aspire CLILatestInstall using the install script
DockerLatestRequired for container resources
Node.js20+LTS version recommended
npm or pnpmLatestPackage manager

The following steps demonstrate how to create a new TypeScript AppHost.

  1. Create and initialize the AppHost:

    Initialize TypeScript AppHost
    aspire new -l typescript --name my-apphost
  2. The following project structure is created:

    • Directorymy-apphost/ - .aspire/ - settings.json - .modules/ Generated SDK (created on first run) - apphost.ts Your AppHost code - apphost.run.json - package.json - tsconfig.json
  3. Review the generated apphost.ts:

    apphost.ts
    import { createBuilder } from './.modules/aspire.js';
    const builder = await createBuilder();
    // Add your resources here, for example:
    // const redis = builder.addRedis("cache");
    // const postgres = builder.addPostgres("db");
    const app = builder.build();
    await app.run();

To add Aspire hosting integrations to your polyglot AppHost, use the aspire add command. The following example adds Redis and Azure Storage integrations.

  1. Add the Redis and Azure Storage integrations:

    Add integrations
    aspire add redis
    aspire add azure-storage

    When you add an integration, the Aspire CLI updates .aspire/settings.json with the package reference, regenerates the TypeScript SDK in the .modules directory, and makes the new APIs available in your AppHost code.

  2. Update apphost.ts to use the integrations:

    apphost.ts
    import { createBuilder } from './.modules/aspire.js';
    const builder = await createBuilder();
    // Add a Redis cache
    const cache = builder.addRedis('cache');
    // Add Azure Storage running as a local emulator
    const storage = builder.addAzureStorage('storage').runAsEmulator();
    const app = builder.build();
    await app.run();
  3. Run the AppHost:

    Run AppHost
    aspire run

    The Aspire CLI starts the .NET AppHost server, pulls the required container images for Redis and the Azure Storage emulator, and opens the Aspire Dashboard.

You can add JavaScript or Node.js applications to your AppHost and have them participate in Aspire’s orchestration, including service discovery and resource references.

  1. Add the JavaScript hosting integration:

    Add JavaScript integration
    aspire add javascript
  2. Update apphost.ts to reference your JavaScript application:

    apphost.ts
    import { createBuilder } from './.modules/aspire.js';
    const builder = await createBuilder();
    // Add a Redis cache
    const cache = builder.addRedis('cache');
    // Add Azure Storage running as a local emulator
    const storage = builder.addAzureStorage('storage').runAsEmulator();
    // Add a Node.js application
    const api = builder
    .addNodeApp('api', '../api', 'server.js')
    .withHttpEndpoint({ port: 3000, env: 'PORT' })
    .withReference(cache);
    const app = builder.build();
    await app.run();

    In this example, the Node.js application at ../api/server.js is registered as a resource named api. It receives a connection string for the Redis cache through service discovery.

    See the JavaScript integration for more configuration options.

If you encounter issues with your polyglot AppHost, this section provides guidance on diagnosing and resolving common problems.

Here are solutions to common problems you may encounter when working with polyglot AppHosts.

Ensure Node.js is installed and available in your PATH:

Verify Node.js installation
node --version
npm --version

Enable polyglot support in the Aspire CLI configuration:

Enable polyglot support
aspire config set features:polyglotSupportEnabled true --global

If you encounter compilation errors in the generated SDK:

  1. Ensure you have the latest version of the Aspire CLI installed
  2. Delete the .modules directory and run aspire run again to regenerate the SDK
  3. Check the Aspire GitHub issues for known problems

Run with debug output to diagnose issues:

Run with debug output
aspire run --debug

Aspire CLI logs are stored at:

Terminal window
$HOME/.aspire/cli/logs/

Polyglot AppHost support is a preview feature. Your feedback helps us improve language support and prioritize new features. Please share your experiences, suggestions, and bug reports on the Aspire GitHub repository.

When reporting issues, please include:

  • The Aspire CLI version (aspire --version)
  • The Node.js version (node --version)
  • Steps to reproduce the issue
  • Any error messages or logs