Note
Access to this page requires authorization. You can try signing in or changing directories.
Access to this page requires authorization. You can try changing directories.
Here are the steps to invoke Node.js from ASP.NET Core Website
Add below line in the ConfiguraServices() in Startup.cs
public
void
ConfigureServices(IServiceCollection services){
services.AddMvc();
services.AddNodeServices();
}
Add constructor in the Controller
public
class
HomeController : Controller{
INodeServices
nodeServices;public
HomeController(INodeServices nodeServices){
this.nodeServices =
nodeServices;}
Call NodeServices as shown below
public
async Task<IActionResult>
About(){
var
msg = await
nodeServices.InvokeAsync<string>("./hello.js",
1);ViewData["Message"] = msg;
return View();
}
Add following code to js file
module.exports = function (callback)
{
var
message = 'Hello
world';callback(null, message);
};
Comments
- Anonymous
November 07, 2017
what in case you got : Microsoft.AspNetCore.NodeServices.HostingModels.NodeInvocationException","Message":"Attempt to connect to Node timed out after 60000mshttps://stackoverflow.com/questions/47172434/azure-react-js-pdf-microsoft-aspnetcore-nodeservices-hostingmodels-nodeinvoc