node-horseman icon indicating copy to clipboard operation
node-horseman copied to clipboard

How to use node-horseman in azure function?

Open karandesai28 opened this issue 8 years ago • 2 comments

I am trying to run node-horseman in httptriggered azure function. I installed node-horseman using npm in azure function directory as well. However various service calls like, Log(), on(), open() etc does not seem to work.

So it will be great if a demo regarding the same is added, or shared for better understanding. Thanks.

karandesai28 avatar Jul 05 '17 11:07 karandesai28

I have never worked with Azure. Did you make sure PhantomJS is installed on there?

awlayton avatar Sep 05 '17 16:09 awlayton

Yes, on Azure Portal via Kudu Cmd, I have installed the PhantomJS as well as Node Horseman and the node modules folder is also created on portal containing the packages. I wrote this sample code in Azure Function after installing all the required dependencies:


var Horseman = require('node-horseman');
var horseman = new Horseman();
horseman
  .open("http://google.com/")
  .pdf("Filename.pdf", {
      format: 'A4',
      orientation: 'portrait',
      margin: '1cm'
  })
  .close()`

I noticed that it does get executed without any error; but Pdf file wasn't generated. I placed success, info and error logs in between. I also added various event listeners mentioned in this part of Node-Horseman documentation. But neither logs printed anything.

I then commented the code, and wrote simple file creation code from azure function which didn't work either. On further researching, I asked on Stack Overflow, whether is it possible to Create and Write any file from Azure Function (Azure function supports Blob and File triggers) and store in File (or Blob) storage directly; to which I got the following reply and comment:

There is a preview of Azure Functions External File bindings to upload file to external storage, but it doesn't work with Azure File Storage. There is a github issue to create a new type of binding for Files.

This led me to conclusion that, we can do file operations from azure function on already existing file (via uploading, or any other similar method) but the creation of File is not possible as of date of writing. However, the feature is being tracked on their github page. Therefore, there is potentially not an issue with Node-Horseman code except that an exception or error should have been thrown on .pdf() when it fails to create file or faces any issue.

karandesai28 avatar Sep 06 '17 03:09 karandesai28