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
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
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
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With