Redigera

Dela via


.NET Aspire Community Toolkit Deno hosting integration

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 Deno package. The extensions package brings the following features:

  • Running Deno applications
  • Running Node.js applications via Deno tasks
  • Ensuring that the packages are installed before running the application via Deno installer

Hosting integration

To get started with the .NET Aspire Community Toolkit Deno extensions, install the 📦 CommunityToolkit.Aspire.Hosting.Deno NuGet package in the AppHost project.

dotnet add package CommunityToolkit.Aspire.Hosting.Deno

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 Deno apps

This integration extension adds support for running a Deno application defined in a script. Since Deno is secure by default, permission flags must be specified in permissionFlags argument of AddDenoApp.

var builder = DistributedApplication.CreateBuilder(args);

builder.AddDenoApp("oak-demo", "main.ts", permissionFlags: ["--allow-env", "--allow-net"])
    .WithHttpEndpoint(env: "PORT")
    .WithEndpoint();

builder.Build().Run();

The preceding code uses the fully qualified switches. Alternatively, you can use the equivalent alias as well. For more information, see Deno docs: Security and permissions.

Run Deno tasks

This integration extension adds support for running tasks that are either specified in a package.json or deno.json.

var builder = DistributedApplication.CreateBuilder(args);

builder.AddDenoTask("vite-demo", taskName: "dev")
    .WithHttpEndpoint(env: "PORT")
    .WithEndpoint();

builder.Build().Run();

Deno package installation

This integration extension adds support for installing dependencies that utilizes deno install behind the scenes by simply using WithDenoPackageInstallation.

Note

This API only works when a deno.lock file present.

var builder = DistributedApplication.CreateBuilder(args);

builder.AddDenoTask("vite-demo", taskName: "dev")
    .WithDenoPackageInstallation()
    .WithHttpEndpoint(env: "PORT")
    .WithEndpoint();

See also