Alethic.Node.AspNetCore 1.0.1-pre.25

This is a prerelease version of Alethic.Node.AspNetCore.
There is a newer prerelease version of this package available.
See the version list below for details.
dotnet add package Alethic.Node.AspNetCore --version 1.0.1-pre.25
                    
NuGet\Install-Package Alethic.Node.AspNetCore -Version 1.0.1-pre.25
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Alethic.Node.AspNetCore" Version="1.0.1-pre.25" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Alethic.Node.AspNetCore" Version="1.0.1-pre.25" />
                    
Directory.Packages.props
<PackageReference Include="Alethic.Node.AspNetCore" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add Alethic.Node.AspNetCore --version 1.0.1-pre.25
                    
#r "nuget: Alethic.Node.AspNetCore, 1.0.1-pre.25"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package Alethic.Node.AspNetCore@1.0.1-pre.25
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=Alethic.Node.AspNetCore&version=1.0.1-pre.25&prerelease
                    
Install as a Cake Addin
#tool nuget:?package=Alethic.Node.AspNetCore&version=1.0.1-pre.25&prerelease
                    
Install as a Cake Tool

Alethic.Node.AspNetCore

Serve a JavaScript application's pages from ASP.NET Core, rendered on Node.js embedded in the process (Alethic.Node). Published as Alethic.AspNetCore.Node through 0.3.

dotnet add package Alethic.Node.AspNetCore
dotnet add package Microsoft.JavaScript.LibNode.linux-x64    # the native runtime: one per platform you deploy to

Use

builder.Services.AddNodeEnginePool(o => o.EngineCount = 2);

var app = builder.Build();
app.UseStaticFiles();
app.UseRouting();                      // explicit, or the fallback endpoint outruns static files

app.MapNodeFetchHandler(o =>
{
    o.Module = NodeModuleSource.FromFile("ssr/app.cjs");
    o.Environment["ApiBaseUri"] = "http://api.internal:8080/";
});

app.Run();

app.cjs is a CommonJS bundle whose default export has a fetch(request, env, ctx) function returning a Response, or is one; Alethic.Node.Http says what it sees. The module loads on every engine at startup. RequestBody and ResponseBody are Streamed unless set to Buffered.

An endpoint per route

MapNodeFetchHandler mounts one fallback endpoint. For an endpoint per route, write an INodeRouteProvider that reads the application's own router, and pass it with the handler:

sealed class MyRouteProvider(NodeEnginePool pool, NodeModuleSource module) : INodeRouteProvider
{
    public Task<IReadOnlyList<RenderRoute>> GetRoutesAsync(CancellationToken cancellationToken = default) =>
        pool.RunAsync(module, exports => { /* read the routes out, as RenderRoutes */ }, cancellationToken);
}

app.MapNode(new FetchRequestHandler(pool, new() { Module = module }), new MyRouteProvider(pool, module));

A RenderRoute has a URLPattern Pattern (/parks/:parkRef), an Id that names the endpoint, and a RenderMode: Server, Prerender, or Client, which is not mapped. MapNodeOptions.ConfigureEndpoint sees each endpoint, for caching or authorization by route; FallbackPattern is the fallback, or null for none.

INodeRequestHandler (PrepareAsync, HandleAsync) is the seam for an application whose server protocol is not a fetch handler.

Constraints

  • Set EngineCount to the cores the process may use; a container reports the host's.
  • Modules are CommonJS, bundled, without code splitting. A rebuilt bundle needs a restart.
  • Module state is shared by every render on an engine.
  • A streamed response cannot change its status after its first byte.
Product Compatible and additional computed target framework versions.
.NET net8.0 is compatible.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed.  net9.0 is compatible.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 was computed.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
1.0.1-pre.27 52 10/4/2026
1.0.1-pre.25 55 10/4/2026
1.0.0 237 10/3/2026
1.0.0-pre.37 49 10/3/2026
1.0.0-pre.34 67 10/3/2026
1.0.0-pre.14 59 10/3/2026