June 04, 2017 by Anuraj
ASP.NET Core NodeServices Node JS
To use Node Services, first you need to include the reference of
Microsoft.AspNetCore.NodeServices package in your project file. You can do this using
dotnet add package Microsoft.AspNetCore.NodeServices command.
Then you need to add the Node Services middleware to the request pipeline. You can do it in your
Now you’re able to get instance of
FromServices attribute to get the instance of `INodeServices’ in your action method. Here is Add method implementation in MVC.
And here is the code of AddModule.js file.
You need to use the type of the result in your
InvokeAsync method, in this example I am using int.
Here is the result of when I am browsing /Home/Add method.
Here is the more useful example, where I am generating the screenshot of web page using
url-to-image node module. To use this, first you need to install this package using npm install command -
npm install --save url-to-image.
Here is the action method, which takes url value from Form values and invokes node module to generate png image.
And here is the UrlPreviewModule.js file.
NodeServices allows ASP.NET Core developers to make use of the entire NPM ecosystem, which gives rise to a huge range of possibilities. You can find the full source code on GitHub.
Happy Programming :)
Copyright © 2024 Anuraj. Blog content licensed under the Creative Commons CC BY 2.5 | Unless otherwise stated or granted, code samples licensed under the MIT license. This is a personal blog. The opinions expressed here represent my own and not those of my employer. Powered by Jekyll. Hosted with ❤ by GitHub