We are trying to implement a proxy using Node.JS.
When we try to use the Node.JS "request" module, Apigee gives an error, which you can see from http://org-test.apigee.net.
The code is very simple and similar to the sample (https://github.com/apigee/node-samples/blob/master/node/mashup/mashup.js).
var request = require('request');
var http = require('http');
var urlparse = require('url');
var util = require('util');
function sendError(resp, code, msg) {
var o = { 'error': msg };
resp.writeHead(code, {'Content-Type': 'application/json'});
resp.end(JSON.stringify(o));
}
var svr = http.createServer(function(req, resp) {
var request = require('request');
var options = {
url: 'https://test.com/api/v2/asa',
method:'POST',
headers: {
'Accept': 'application/json',
'Accept-Charset': 'utf-8',
'Api-Key': '33769302e0812dsadasdadd'
},
json:true,
body:{resource:{
group_name:'testing'
}}
};
request.post(options, function (err,res,body) {
console.log(body)
});
resp.writeHead(200, {'Content-Type': 'application/json'});
resp.end(JSON.stringify("{}"));
});
svr.listen(9000, function() {
console.log('Node Mashup sample app is running on port 9000');
});
When I deploy my application, I use the following command:
apigeetool deploynodeapp -u email -p password -o org -e test -n testapp -d . -m app.js
Can you help me with this issue, or guide me to the people that can help me resolve the issue?
Solved! Go to Solution.
I think this is a compatibility problem, because the current version of the request module requires node version >= 4.
https://github.com/request/request/blob/master/package.json
"node": ">= 4"
But, Edge currently supports Node.js 0.10.32.
https://docs.apigee.com/api-services/content/understanding-edge-support-nodejs-modules
You may consider to use alternative ways to make http request, e. g. 'native' http.request.
UPDATE:
I've checked the GitHub repo for the request module. The last version that was supported on node 0.10.x was version 2.71.0
Therefore, to use the request module on Apigee Edge nodes targets, update your dependencies in package.json like so:
"request": "2.71.0"
https://github.com/request/request/tree/v2.71.0