Bruce965.NodeDevServer 1.0.0

dotnet add package Bruce965.NodeDevServer --version 1.0.0
NuGet\Install-Package Bruce965.NodeDevServer -Version 1.0.0
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="Bruce965.NodeDevServer" Version="1.0.0" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Bruce965.NodeDevServer --version 1.0.0
#r "nuget: Bruce965.NodeDevServer, 1.0.0"
#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.
// Install Bruce965.NodeDevServer as a Cake Addin
#addin nuget:?package=Bruce965.NodeDevServer&version=1.0.0

// Install Bruce965.NodeDevServer as a Cake Tool
#tool nuget:?package=Bruce965.NodeDevServer&version=1.0.0

Bruce965.NodeDevServer

Automatically start a Node development server alongside with an ASP.NET Core application.

Requirements

The .NET SDK must be installed.

Node.js also needs to be installed in order to start a Node development server.

Usage

If you don't have one already, create a new ASP.NET Core application.

dotnet new web --output MyAspNetCoreApp

Add the Bruce965.NodeDevServer NuGet package to your ASP.NET Core application.

dotnet add MyAspNetCoreApp package Bruce965.NodeDevServer

If you don't have one already, create a new Node.js application. You may use Vite or any other framework at your preference.

npm create -y vite -- my-frontend --template vanilla

Configure the Node development server in your Program.cs file.

WebApplicationBuilder builder = WebApplication.CreateBuilder(args);

// Configure the local Node development server.
builder.Services.AddNodeDevServer(options =>
{
    // You may need to tweak these options if you don't use Vite.
    options.HostUri = "http://localhost:5173";
    options.Path = "../my-frontend";
    options.LaunchScript = "dev";
    options.PackageManagers = ["yarn", "npm"];
});

WebApplication app = builder.Build();

// Some Node.js frameworks require this in order to support hot-reload.
app.UseWebSockets();

app.UseRouting();
app.UseEndpoints(_ => {});

if (app.Environment.IsDevelopment())
{
    // In development, forward all requests to Node.js.
    // The first request will automatically launch it.
    app.UseNodeDevServer();
}
else
{
    // In production, use the pre-built files.
    app.UseStaticFiles();
}

app.Run();

License

This project is licensed under the MIT license.

Some components may be available elsewhere under different license terms, please refer to the individual source files.

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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
  • net8.0

    • No dependencies.

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.0 86 5/4/2024