Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Azure Web App WebJob not installing node packages

I am trying to create a webjob using nodejs, the scripts use various node modules, however when the job runs it doesn't appear to install the packages up front.

The zip file i upload has a package.json with all the dependencies and a server.js in the root of the zip, the script get executed but as per the log below it can't find the modules to run.

I am getting the following output in the log.

[07/28/2015 07:36:14 > 5fabb6: SYS INFO] Status changed to Initializing
[07/28/2015 07:36:14 > 5fabb6: SYS INFO] Run script 'server.js' with script host - 'NodeScriptHost'
[07/28/2015 07:36:14 > 5fabb6: SYS INFO] Status changed to Running
[07/28/2015 07:36:15 > 5fabb6: ERR ] 
[07/28/2015 07:36:15 > 5fabb6: ERR ] module.js:340
[07/28/2015 07:36:15 > 5fabb6: ERR ]     throw err;
[07/28/2015 07:36:15 > 5fabb6: ERR ]           ^
[07/28/2015 07:36:15 > 5fabb6: ERR ] Error: Cannot find module 'sendgrid'
[07/28/2015 07:36:15 > 5fabb6: ERR ]     at Function.Module._resolveFilename (module.js:338:15)
[07/28/2015 07:36:15 > 5fabb6: ERR ]     at Function.Module._load (module.js:280:25)
[07/28/2015 07:36:15 > 5fabb6: ERR ]     at Module.require (module.js:364:17)
[07/28/2015 07:36:15 > 5fabb6: ERR ]     at require (module.js:380:17)
[07/28/2015 07:36:15 > 5fabb6: ERR ]     at Object.<anonymous> (D:\home\site\wwwroot\App_Data\jobs\triggered\TestWebJob\dist\services\email.service.js:4:16)
[07/28/2015 07:36:15 > 5fabb6: ERR ]     at Module._compile (module.js:456:26)
[07/28/2015 07:36:15 > 5fabb6: ERR ]     at Object.Module._extensions..js (module.js:474:10)
[07/28/2015 07:36:15 > 5fabb6: ERR ]     at Module.load (module.js:356:32)
[07/28/2015 07:36:15 > 5fabb6: ERR ]     at Function.Module._load (module.js:312:12)
[07/28/2015 07:36:15 > 5fabb6: ERR ]     at Module.require (module.js:364:17)
[07/28/2015 07:36:15 > 5fabb6: SYS INFO] Status changed to Failed
[07/28/2015 07:36:15 > 5fabb6: SYS ERR ] Job failed due to exit code 8
like image 605
JohnC Avatar asked Jul 28 '15 07:07

JohnC


3 Answers

The best way to do this appears to be manually ftping the node_modules up into the correct folder. As per https://github.com/projectkudu/kudu/wiki/Web-jobs#copying-files-directly-in-their-proper-location

What i did was to create the webjob without the node_modules folder and then ftp up the files separately.

Upload your node module to the following folder via ftp

  • /site/wwwroot/node_modules

ftp view of azure node website

like image 182
JohnC Avatar answered Sep 28 '22 12:09

JohnC


You shouldn't have to upload node modules. That defeats the purpose of a simple git push. And you don't want to include node modules in your git repo either.

The "secret" is to add the node module dependencies to your main project package.json, then add your web jobs into your base project folder with this structure:

App_Data\jobs\continuous\ [jobname]

The web job in this folder need not have a package.json or node modules because it uses the modules specified in the main project package.json. Its main file should be called "run.js".

I just discovered this today and it's a shame that you have to dig through the entire internet before you learn that you don't have to manually upload web jobs to the Azure portal. Microsoft, please add documentation for these kinds of things for people using node.js. Azure is an awesome platform! But the barrier to entry for Azure with node.js is high because of things like this.

See this helpful article for more details:

http://blog.amitapple.com/post/74215124623/deploy-azure-webjobs/#.V6JkF7grKUl

like image 20
Sam Avatar answered Sep 28 '22 13:09

Sam


WebJobs won't run npm before the executing the script, so make sure to include the modules you application depends on in the upload, e.g. include node_modules in the zip file you upload through the portal.

like image 21
MrBink Avatar answered Sep 28 '22 12:09

MrBink