Run DLL on Azure Cloud Service - node.js

I've worked a lot with Azure websites but not cloud services. I need to spin up a cloud service that uses a third party dll to generate pdfs (http://wkhtmltopdf.org/). However, I would like to write this server in nodejs and almost all examples are in asp.net. I just need to know how to reference and execute this dll (or exe, if that's easier) from node js in an Azure Web Role when a request comes in. I'd greatly appreciate any pointers.
Thanks,
Sam
EDIT: It's not necessarily a matter of referencing or using the dll from the code that I will have an issue with. It's how to INSTALL the dll on an Azure web role. All you can do in an Azure cloud service / web role is upload the project package but no explanation on how to add a dll or exe (except in asp.net, which I am not using. I'm using nodejs).

You can put the installer in your web role package, and set up a startup task in the ServiceDefinition.csdef file for the roles.
Here is the sample on official site Install .NET on a Cloud Service Role, which is guiding to install .NET in Cloud service, the steps and scenario should be the same.

There are a lot of wrappers for wkhtmltopdf. This one is nice and pipable (you can stream the output directly to your client):
var wkhtmltopdf = require('wkhtmltopdf');
// URL
wkhtmltopdf('http://google.com/', { pageSize: 'letter' })
.pipe(fs.createWriteStream('out.pdf'));
// HTML
wkhtmltopdf('<h1>Test</h1><p>Hello world</p>')
.pipe(res);
You have to install wkhtmltopdf (the command line tool) first of course.

Assuming that the dll is a managed assembly (i.e. an assembly compiled using .net), you can use edge.js to get NodeJS to interact with the dll.
If it is an exe, you can execute the process via NodeJS's asynchronous process creation API.

Related

Publish Windows service in Microsoft store with NodeJS or Electron

I'm looking for a the golden advice.
I've created an app that listens to websockets over a certain port and then sends commands to a native module (wrapped by NodeJS). now all this is done in NodeJS app. and packed in exe file (with two extra files for the native module ".dll and .napi")
now I want two things:
Run this app as a windows service in the background.
Package it in an installer that should stop the service (if exists), install the new update, then re-run the service. this app will be published in Microsoft store as appx.
I'm new to all of this so I feel lost while trying to know which is the best approach with my little knowledge.
I'm a bit confused between NodeJS and ElectronJS, some people say electron is not the best choice for services, but electron-builder is a great tool for packaging.
Conclusion: I want to publish my app to Microsoft store (already bought a developer account), and to run it as a service (no GUI). and the code is written in JS (node or electron)
Thanks in advance

Using Azure SDK for JS to create .NET 4.x App Service

I'm starting to wonder whether this is the right tool for the job, still here goes.
I'm attempting to automate the creation of our Azure Test environment using Azure SDK for JS. The environment spans many services (as you can imagine), including Classic ASP.NET app services.
Node is my safe space, so that is why I started with the JS SDK.
I have started scripting the creation of an app service using WebSiteManagementClient.webApps.createOrUpdate. I'm confused though, there is seemingly no way to configure any of the following:
Which app service plan the app service should be connected to. This feels fundamental.
The operating system, Windows or Linux.
The stack version, .NET 4.8, .NET Core, or whatever.
Is it possible to configure the above using the JS SDK, or am I going to have find another approach?
Update 23/03/21
Untested, but these are my findings so far:
App Service Plan - The plan is set using the serverFarmId property of the Site interface.
Operating system - Assuming Windows as the default, if you want a Linux app service, you change the kind property of Site from app, to app,linux.
Stack & version - In the SiteConfig interface, you have linuxFxVersion and windowsFxVersion. Again, I think the assumption is 'latest .NET' (e.g. .NET 4.8). For .NET Core 3.1, the setting looks to be DOTNETCORE|3.1.
It can be achieved using js SDK. I checked the source code and it is ok. But I don't recommend to use js sdk to do this.
Because you need to call the SDK, there are many internal logics that you need to code. This will waste a lot of your time. So I recommend you to use restapi.
The restapi method name is similar to the naming in the SDK, mainly because you can test api interfaces online to achieve the functions you want. So you can selectively choose the method you want to achieve the function you want.
Official doc
Web Apps - Create Or Update
As for your concerns, you only need to write all the configuration in json format and put it in the request body.
Tips:
First use the online interface, encode the json format, create a webapp according to your needs, and then integrate it into your code.

Is it possible to publish a .net core web api to azure functions?

I've recently switched jobs from a AWS shop to an Azure shop, both using dotnet. AWS publishes Amazon.Lambda.AspNetCoreServer, which is a magic Nuget package that allows you to write a plain ol' ASP.NET core Web API and deploy it as into a lambda with only a few lines on config. I really loved this pattern because it allows developers to just write a normal web api without having the host runtime leak into their coding.
Does anything like this exist in Azure? Even something that is community supported? Or is there some any way to achieve something like this in Azure Functions?
Unfortunately there is no simple way to do that since Azure function format is a bit different.
[FunctionName(nameof(GetAll))]
public IActionResult GetAll([HttpTrigger("get", Route = "entity")]HttpRequest request)
Then it will generate json with meta data for AF.
If you wish to host pure .net core without any changes I would look into Containers option
PS0: Theoretically it would be possible to do it with little bit of reflection. For instance you create project with all your Asp.Net core apis, which you can use in asp.net core hosting. Then you write tool which grabs your dll and using reflection you find all actions in your controllers and generate code for AF
PS1: Have a look https://github.com/tntwist/NL.Serverless.AspNetCore

How to use GCP Runtime Configurator from Node.js?

I'm working on a Node.js application hosted on Google Cloud, using Google Application Engine. The app has a few settings like the following:
const TASK_BATCH_SIZE = 50;
Currently, every time we need to change some settings like that one to do some tests we need to re-deploy the app, and that happens very often. We are looking for some alternatives inside the Google Cloud ecosystem that allows us to configure our running services without needing to re-deploy.
One of the things we found in the docs was Runtime Configurator, which still seems to be a beta product. For Node.js specifically nodejs-rcloadenv is the only client library we found, but doesn't seem to support the Watcher / Waiter concepts described in the Runtime Configurator docs or any other way to subscribe to variable changes in a configuration resource.
Is Runtime Configurator the solution to our problem? Are there any other services inside the Google Cloud ecosystem, or any other library for Node.js that could help us with this?
If you want to update or to make some settings changes in the service, you need to re-delpoy the service.
You can't use Runtime Configurator as it's for Compute Engine and not for App Engine.
You can create a feature request on Google's Public Issue Tracker for your issue ( to update configurations without re-deploying the service).

Azure: Application Insights. Are the ai.x.xx.x-buildxxxxx.js file required?

After enabling Application Insights on my MVC web app I see that a file called ai.0.22.8-build00154.js was added to the /Scripts folder (however, it was not included to the .csproj).
In addition I do not see this file referenced anywhere in the project.
When I run the web app I do see data being sent to my Application Insights instance on Azure.
* Question *
Is this javascript file even required?
Note that I do have the script snippet at the end of the section (per App. Insights documentation).
This file is not required. It is included in case you decide to host Application Insights JS SDK yourself and not use the hosted version on CDN (http://az416426.vo.msecnd.net/scripts/a/ai.0.js). The snippet is referencing this version, so in case you decide to host AI JS SDK script yourself, you also need to update the snippet.
It is recommended that you are referencing the version on the CDN as this is the way to get all the latest updates automatically.
Yes I believe it is required, it's the Nuget package. The filename you have up there seems to match up with the package.

Resources