Using other npm modules in APIGEE Edge cloud version

Not applicable
I tried to use npm module 'request-replay' in Apigee Edge cloud.But its throwing me error like "Error: Cannot find module 'request-replay' ".How to include this module in the cloud version of APIGEE Edge for the use in API Proxies? I also tried using npm module 'request'.But this time its not "Cannot find module".Instead errors are not clear."Script node executed prematurely: Script HTTPReq.js exited with status code 0" .Not sure whether this is also same issue. Please suggest what should I do to fix these issues.
Solved Solved
0 13 308
1 ACCEPTED SOLUTION

  • Add the dependency to package.json file
  • Re-Deploy Node APP
  • Call API here with command=install

View solution in original post

13 REPLIES 13

Dear @RadR4 , Check here Deploying a standalone Node.js app for more information on using node applications in Apigee Edge. Cheers, Anil Sagar

@Anil Sagar ,I tried as you mentioned in the link you have given.I replaced the organisation name,API name,and revision number. https://api.enterprise.apigee.com/v1/organizations...<organisation>/apis/ReqRep/revisions/1/npm Gave command=install in Post. Its showing HTTP 200OK with npm command usage details. So,I thought request-reply module would have been installed.But when I tried to test my API,same module not found error is coming...

@RadhamaniRamadoss , Do you mean using npm modules in Node.JS app hosted on Apigee Edge or Using it in an Existing API Proxy Javascript Policy ?

I meant using npm modules in Node.JS app hosted on Apigee Edge

Thank you for more details. Sorry for confusion and too many edits to the answer, Please check latest answer. That should solve the issue as far as i know.

  • Add the dependency to package.json file
  • Re-Deploy Node APP
  • Call API here with command=install

This is the procedure we do in node js usually to add dependency. But as I am working on cloud version(trial),I am not sure whether this feature is still available. Where can I find the package.json file in cloud trial version?

  • Download the bundle using the Edge UI
  • navigate to resources/node in your local machine
  • install request-replay node module using npm
npm install request-replay
  • Zip the bundle, make sure directory name is apiproxy before zipping same
  • Upload the new revision using Edge UI
1079-screen-shot-2015-09-03-at-63456-pm.png

Thanks a lot. I will try and update.

Anytime 🙂 Keep us posted ..

This has fixed the reference issue for request-replay module.

But now I am facing new issue,

*** Starting script *** Script ReqRep.js exited with status code 0

My ReqRes.js script goes as below.This is the same program given in the link https://github.com/IndigoUnited/node-request-replay/blob/master/README.md.Even the Node.js logs does not present any other useful information to fix the issue.Could not find any relevant links in community posts for similar issue.Could you please let me know what could be the issue?

var fs = require('fs');
var request = require('request');
var replay = require('request-replay');
 
// Note that the options argument is optional 
// Accepts the same options the retry module does and an additional 
// errorCodes array that default to ['EADDRINFO', 'ETIMEDOUT', 'ECONNRESET', 'ESOCKETTIMEDOUT'] 
replay(request('http://google.com/doodle.png', function (err, response, body) {
    // Do things 
}), {
    retries: 10,
    factor: 3
})
.on('replay', function (replay) {
    // "replay" is an object that contains some useful information 
    console.log('request failed: ' + replay.error.code + ' ' + replay.error.message);
    console.log('replay nr: #' + replay.number);
    console.log('will retry in: ' + replay.delay + 'ms')
})
 				

Dear @RadhamaniRamadoss ,

Glad this issue is resolved. To make sure not to loose the context, please post different question. Also, Accept the answer so that it will be helpful for others looking for same.

Cheers,

Anil Sagar

Sure...Will do.Thanks