Search code examples
node.jsazureazure-webjobswebjob

Node.js project zip failed to upload as Azure WebJob


Please don't close this question without reading.

I have got a regular Node.js project with an index.js and a bunch of node_modules, one of which is azure-storage to download a file.. I have compressed it into .zip and trying to upload it as an Azure WebJob.. but it is failing every time.

What it does is, there is one empty directory inside my Node.js project. I have written some code which downloads a csv file from azure storage into the local directory and converts each row into an INSERT statement.

Came across a couple of threads referring to the same prob.. what I have tried is:

  1. npm dedupe - This was suggested somewhere as node_module directory tree can recursively exceed the length allowed in Windows - Didn't work for me
  2. Trashed everything inside node_modules (just to check if #1 is really the problem for me) - Same error
  3. Uploaded the index.js file only - Worked :/

Solution

  • It's been two days and since I didn't see anyone posting a solution here, I gotta assume that no one has run into this problem yet, or maybe very few people are using Node.js + Azure WebJobs.

    The good news is, I found the problem and now I have got my Node.js WebJob up and running now inside an Azure App Service. (And the bad news is I couldn't find anything in the logs I downloaded, not sure if I missed anything in the logs).

    So, here's how I did it, in case anyone tumbles upon the same problem some day...

    First, don't use index.js. Use run.js as the entry point to your WebJob, and in your package.json file, have the entry { ... "main": "run.js", ... }

    This is pretty simple.

    Where I went wrong was, I was compressing my Node.js project directory in to a .zip file and this is where all hell broke loose. Whenever I uploaded this .zip as an Azure WebJob in my App Service.. Azure tried starting it for some time and then ended with an error saying, "failed to add webjob".

    Solution: Get into the Node.js project directory and "select all" files + directories inside it and then compress the selection. Instead of compressing the Node.js project directory, compress its contents :)

    Then upload the compressed .zip as an Azure WebJob in your App Service and it will work like a charm!

    Some additional info: This is how my Node.js project directory looked like roughly.

    • _1_my_directory
    • node_modules
    • run.js
    • supporting-util-1.js
    • supporting-util-2.js
    • app.config
    • some-other.config