title | description | ms.date |
---|---|---|
Node.js hosting extensions |
Learn about the .NET Aspire Community Toolkit Node.js hosting extensions package which provides extra functionality to the .NET Aspire NodeJS hosting package. |
10/11/2024 |
[!INCLUDE includes-hosting]
[!INCLUDE banner]
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)
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
<PackageReference Include="CommunityToolkit.Aspire.Hosting.NodeJS.Extensions"
Version="*" />
For more information, see dotnet add package or Manage package dependencies in .NET applications.
The following sections detail various usages, from running Vite applications to using 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();
var builder = DistributedApplication.CreateBuilder(args);
builder.AddPnpmApp("pnpm-demo")
.WithExternalHttpEndpoints();
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();
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.