2

I have a .NET Standard project that includes a bunch of models and methods, and I want to use them in a NodeJS application written in TypeScript. All the samples I see for Blazor JavaScript interop integrate with JS through Razor files, but I couldn't find any samples that show how to integrate .NET code with NodeJS. Is this possible at all and if yes, how? Thanks!

1 Answer 1

2

This is not possible Client-side Blazor works only in browser and interop is only with browser JS, since it is browser who run WASM and JS inside themselves.

Previously you can theoretically integrate some NodeJS inside ASP.NET Core application using NodeServices, but they are would be obsolete in .NET Core 3. See https://github.com/aspnet/AspNetCore/issues/12890

If you want to run some code from Blazor inside NodeJS likely you have to create separate command line application and communicate between it and your NodeJS application.

Sign up to request clarification or add additional context in comments.

4 Comments

WebAssembly is supported in NodeJS since version 8. See "The WebAssembly JavaScript API" section here that shows how to run a .wasm file in nodejs. So I guess all it should take is to compile C# to wasm. Is that possible with Blazor?
In more details, Client Side Blazor is Mono which executes the C# DLLs. So likely you can make Client Side Blazor run inside NodeJS, but what it gives to you? You will run Mono inside WASM. To call some C# code, you likely has to either write some additional C# code to run it inside Mono WASM, and at that point you can just run C# code under Mono/.NET Core and communicate somehow with NodeJS. Client Side Blazor in its current state does not designed for your use-case.
@orad With what @codevision said, that would mean you need to ship the Mono environment (compiled to WASM), all the DLLs required (including all the system stuff) on your own. When building the client-side blazor app, the bin\Debug\netstandard2.0\dist folder will hold all required files, including the DLLs, as well as the Mono runtime as WASM.
This is not Blazor but you can run C# inside NodeJS github.com/ncave/dna-redux

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.