Deno integration
Dieser Inhalt ist noch nicht in deiner Sprache verfügbar.
The Aspire Deno hosting integration enables you to run Deno applications — a modern, secure JavaScript and TypeScript runtime — alongside your other resources in the AppHost.
Hosting integration
Section titled “Hosting integration”aspire add communitytoolkit-denoDie Aspire CLI ist interaktiv; das passende Suchergebnis wählen, wenn gefragt:
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”Use the AddDenoApp extension method to add a Deno application to your AppHost:
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>("api") .WithReference(denoApp);
builder.Build().Run();The AddDenoApp method accepts the following parameters:
| Parameter | Description |
|---|---|
name | The name of the resource in the Aspire dashboard. |
workingDirectory | Path to the directory containing your Deno application. |
scriptPath | Path to the Deno script to run, relative to the working directory. |
args | Deno permission flags and other arguments passed at startup. |
Add Deno task
Section titled “Add Deno task”To run a task defined in 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");
builder.Build().Run();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, call WithDenoPackageInstallation:
var builder = DistributedApplication.CreateBuilder(args);
var denoApp = builder.AddDenoApp( name: "deno-api", workingDirectory: "../deno-app", scriptPath: "main.ts", args: ["--allow-net", "--allow-env"]) .WithDenoPackageInstallation() .WithHttpEndpoint(port: 8000, env: "PORT");
builder.Build().Run();Configure HTTP endpoints
Section titled “Configure HTTP endpoints”Deno applications read the port to listen on from an environment variable. Use WithHttpEndpoint to expose a port and inject it into the process:
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.Build().Run();Inside your Deno application, read the PORT environment variable using Deno.env.get:
const port = Number(Deno.env.get("PORT")) || 8000;
Deno.serve({ port }, () => { return new Response("Hello from Deno!");});
console.log(`Server listening on port ${port}`);