JavaScriptHostingExtensions.AddNodeApp Method
Definition
Important
Some information relates to prerelease product that may be substantially modified before it’s released. Microsoft makes no warranties, express or implied, with respect to the information provided here.
Adds a node application to the application model. Node should be available on the PATH.
public static Aspire.Hosting.ApplicationModel.IResourceBuilder<Aspire.Hosting.JavaScript.NodeAppResource> AddNodeApp(this Aspire.Hosting.IDistributedApplicationBuilder builder, string name, string appDirectory, string scriptPath);
static member AddNodeApp : Aspire.Hosting.IDistributedApplicationBuilder * string * string * string -> Aspire.Hosting.ApplicationModel.IResourceBuilder<Aspire.Hosting.JavaScript.NodeAppResource>
<Extension()>
Public Function AddNodeApp (builder As IDistributedApplicationBuilder, name As String, appDirectory As String, scriptPath As String) As IResourceBuilder(Of NodeAppResource)
Parameters
- builder
- IDistributedApplicationBuilder
The IDistributedApplicationBuilder to add the resource to.
- name
- String
The name of the resource.
- appDirectory
- String
The path to the directory containing the node application.
- scriptPath
- String
The path to the script relative to the app directory to run.
Returns
A reference to the IResourceBuilder<T>.
Examples
Add a Node app to the application model using yarn and 'yarn run dev' for running during development:
var builder = DistributedApplication.CreateBuilder(args);
builder.AddNodeApp("frontend", "../frontend", "app.js")
.WithYarn()
.WithRunScript("dev");
builder.Build().Run();
Remarks
This method executes a Node script directly using node script.js. If you want to use a package manager you can add one and configure the install and run scripts using the provided extension methods.
If the application directory contains a package.json file, npm will be added as the default package manager.