Skip to content

Latest commit

 

History

History
95 lines (62 loc) · 3.31 KB

hosting-deno.md

File metadata and controls

95 lines (62 loc) · 3.31 KB
title description ms.date
.NET Aspire Community Toolkit Deno hosting integration
Learn about the .NET Aspire Community Toolkit Deno hosting extensions package which provides functionality to run Deno applications and tasks.
10/25/2024

.NET Aspire Community Toolkit Deno hosting integration

[!INCLUDE includes-hosting]

[!INCLUDE banner]

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
<PackageReference Include="CommunityToolkit.Aspire.Hosting.Deno"
                  Version="*" />

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