Deno integration
The Aspire Deno hosting integration enables you to run Deno applications alongside your Aspire projects in the Aspire app host. Deno is a modern JavaScript and TypeScript runtime.
Hosting integration
Section titled “Hosting integration”To get started with the Aspire Deno hosting integration, install the CommunityToolkit.Aspire.Hosting.Deno NuGet package in the app host project.
aspire add communitytoolkit-denoThe Aspire CLI is interactive, be sure to select the appropriate search result when prompted:
Select an integration to add:
> communitytoolkit-deno (CommunityToolkit.Aspire.Hosting.Deno)> Other results listed as selectable options...#:package CommunityToolkit.Aspire.Hosting.Deno@*<PackageReference Include="CommunityToolkit.Aspire.Hosting.Deno" Version="*" />Add Deno app
Section titled “Add Deno app”To add a Deno application to your app host, use the AddDenoApp extension method:
var builder = DistributedApplication.CreateBuilder(args);
var denoApp = builder.AddDenoApp( name: "deno-api", workingDirectory: "../deno-app", scriptPath: "main.ts", args: ["--allow-net", "--allow-env"]) .WithHttpEndpoint(port: 8000, env: "PORT");
builder.AddProject<Projects.ExampleProject>() .WithReference(denoApp);
// After adding all resources, run the app...The AddDenoApp method requires:
- name: The name of the resource in the Aspire dashboard
- workingDirectory: The path to the directory containing your Deno application
- scriptPath: The path to the Deno script to run (relative to working directory)
- args: Permission flags required by Deno (e.g.,
--allow-net,--allow-env)
Add Deno task
Section titled “Add Deno task”To run a task defined in package.json or deno.json, use the AddDenoTask extension method:
var builder = DistributedApplication.CreateBuilder(args);
var denoApp = builder.AddDenoTask( name: "deno-api", workingDirectory: "../deno-app", taskName: "start") .WithHttpEndpoint(port: 8000, env: "PORT");
// After adding all resources, run the app...This runs deno task start in the specified working directory.
Package installation
Section titled “Package installation”To ensure packages are installed before running your Deno application, use the WithDenoPackageInstallation method:
var builder = DistributedApplication.CreateBuilder(args);
var denoApp = builder.AddDenoApp("deno-api", "../deno-app", "main.ts", ["--allow-net", "--allow-env"]) .WithDenoPackageInstallation() .WithHttpEndpoint(port: 8000, env: "PORT");
// After adding all resources, run the app...Configure endpoints
Section titled “Configure endpoints”Deno applications typically use environment variables to configure the port they listen on. Use WithHttpEndpoint to configure the port and set the PORT environment variable:
var builder = DistributedApplication.CreateBuilder(args);
var denoApp = builder.AddDenoApp("deno-api", "../deno-app", "main.ts", ["--allow-net", "--allow-env"]) .WithHttpEndpoint(port: 8000, env: "PORT");
// After adding all resources, run the app...Your Deno application can read the PORT environment variable:
const port = Number(Deno.env.get("PORT")) || 8000;
Deno.serve({ port }, () => { return new Response("Hello from Deno!");});
console.log(`Server listening on port ${port}`);Working directory
Section titled “Working directory”The workingDirectory parameter specifies where the Deno application is located. The Aspire app host will run Deno commands in this directory.