Giter Club home page Giter Club logo

nodedevserver's Introduction

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.

nodedevserver's People

Contributors

bruce965 avatar

Stargazers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.