.NET Aspire Community Toolkit Node.js hosting extensions
Includes: Hosting integration not Client integration
Note
This integration is part of the .NET Aspire Community Toolkit and isn't officially supported by the .NET Aspire team.
In this article, you learn about the .NET Aspire Community Toolkit Node.js hosting extensions package which provides extra functionality to the .NET Aspire NodeJS hosting package. The extensions package brings the following features:
- Running Vite applications
- Running Node.js applications using Yarn and pnpm
- Ensuring that the packages are installed before running the application (using the specified package manager)
Hosting integration
To get started with the .NET Aspire Community Toolkit Node.js hosting extensions, install the 📦 CommunityToolkit.Aspire.Hosting.NodeJS.Extensions NuGet package in the AppHost project.
dotnet add package CommunityToolkit.Aspire.Hosting.NodeJS.Extensions
For more information, see dotnet add package or Manage package dependencies in .NET applications.
Example usage
The following sections detail various usages, from running Vite applications to using specific package managers.
Run specific package managers
This integration extension adds support for running Node.js applications using Yarn or pnpm as the package manager.
var builder = DistributedApplication.CreateBuilder(args);
builder.AddYarnApp("yarn-demo")
.WithExternalHttpEndpoints();
Run Vite apps
This integration extension adds support for running the development server for Vite applications. By default, it uses the npm
package manager to launch, but this can be overridden with the packageManager
argument.
var builder = DistributedApplication.CreateBuilder(args);
builder.AddViteApp("vite-demo")
.WithExternalHttpEndpoints();
builder.AddViteApp("yarn-demo", packageManager: "yarn")
.WithExternalHttpEndpoints();
builder.AddViteApp("pnpm-demo", packageManager: "pnpm")
.WithExternalHttpEndpoints();
builder.Build().Run();
Install packages
When using the WithNpmPackageInstallation
, WithYarnPackageInstallation
or WithPnpmPackageInstallation
methods, the package manager is used to install the packages before starting the application. These methods are useful to ensure that packages are installed before the application starts, similar to how a .NET application would restore NuGet packages before running.