# Node.js "request" module problem

**URL:** <https://discuss.google.dev/t/node-js-request-module-problem/4117>\
**Category:** Apigee\
**Tags:** api-runtime\
**Created:** [January 3, 2018, 5:22pm UTC](https://discuss.google.dev/t/node-js-request-module-problem/4117 "2018-01-03T17:22:10Z")\
**Posts on this page:** 13\
**Page:** 1

<div class="post-metadata">

**Author:** ![anonymous8](https://avatars.discourse-cdn.com/v4/letter/a/7cd45c/32.png) [@anonymous8](https://discuss.google.dev/u/anonymous8)\
**Post date:** [January 3, 2018, 5:22pm UTC](https://discuss.google.dev/t/node-js-request-module-problem/4117/1 "2018-01-03T17:22:10Z")

</div>

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](http://org-test.apigee.net).

The code is very simple and similar to the sample ([node-samples/node/mashup/mashup.js at master · apigee/node-samples · GitHub](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](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?

---

<div class="post-metadata">

**Author:** ![anonymous8](https://avatars.discourse-cdn.com/v4/letter/a/7cd45c/32.png) [@anonymous8](https://discuss.google.dev/u/anonymous8)\
**Post date:** [January 3, 2018, 6:17pm UTC](https://discuss.google.dev/t/node-js-request-module-problem/4117/2 "2018-01-03T18:17:54Z")

</div>

Hi [@Uurtsaikh Jamsrandorj](https://community.apigee.com/users/11351/vp-is.html), did you include the request module as part of the dependencies in your package.json descriptor file?

---

<div class="post-metadata">

**Author:** ![anonymous8](https://avatars.discourse-cdn.com/v4/letter/a/7cd45c/32.png) [@anonymous8](https://discuss.google.dev/u/anonymous8)\
**Post date:** [January 3, 2018, 6:25pm UTC](https://discuss.google.dev/t/node-js-request-module-problem/4117/3 "2018-01-03T18:25:41Z")

</div>

Yes, I did.

Here is my package.json file.

```auto
{
  "name": "test",
  "version": "0.0.0",
  "description": "test",
  "main": "app.js",
  "private": true,
  "dependencies": { 
    "request": "2.x.x"
  }
}

```

---

<div class="post-metadata">

**Author:** ![anonymous8](https://avatars.discourse-cdn.com/v4/letter/a/7cd45c/32.png) [@anonymous8](https://discuss.google.dev/u/anonymous8)\
**Post date:** [January 3, 2018, 9:19pm UTC](https://discuss.google.dev/t/node-js-request-module-problem/4117/4 "2018-01-03T21:19:40Z")

</div>

You wrote:

Apigee gives an error,

What error does Apigee give? Can you tell us exactly the error message you see? And when do you see it - after running which command or request? And where do you see it?

---

<div class="post-metadata">

**Author:** ![anonymous8](https://avatars.discourse-cdn.com/v4/letter/a/7cd45c/32.png) [@anonymous8](https://discuss.google.dev/u/anonymous8)\
**Post date:** [January 3, 2018, 9:20pm UTC](https://discuss.google.dev/t/node-js-request-module-problem/4117/5 "2018-01-03T21:20:32Z")

</div>

Hi, this answer is now marked “accepted”.

Have you solved your problem? what was the solution?

If not, please provide additional information - specifically what error are you seeing?

---

<div class="post-metadata">

**Author:** ![anonymous8](https://avatars.discourse-cdn.com/v4/letter/a/7cd45c/32.png) [@anonymous8](https://discuss.google.dev/u/anonymous8)\
**Post date:** [January 3, 2018, 10:29pm UTC](https://discuss.google.dev/t/node-js-request-module-problem/4117/6 "2018-01-03T22:29:40Z")

</div>

No, I have not solved yet my problem

---

<div class="post-metadata">

**Author:** ![anonymous8](https://avatars.discourse-cdn.com/v4/letter/a/7cd45c/32.png) [@anonymous8](https://discuss.google.dev/u/anonymous8)\
**Post date:** [January 3, 2018, 10:40pm UTC](https://discuss.google.dev/t/node-js-request-module-problem/4117/7 "2018-01-03T22:40:04Z")

</div>

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](https://github.com/request/request/blob/master/package.json)

```auto
"node": ">= 4"

```

But, Edge currently supports Node.js 0.10.32.

[https://docs.apigee.com/api-services/content/understanding-edge-support-nodejs-modules](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:

```auto
"request": "2.71.0"

```

[https://github.com/request/request/tree/v2.71.0](https://github.com/request/request/tree/v2.71.0)

---

<div class="post-metadata">

**Author:** ![anonymous8](https://avatars.discourse-cdn.com/v4/letter/a/7cd45c/32.png) [@anonymous8](https://discuss.google.dev/u/anonymous8)\
**Post date:** [January 3, 2018, 10:41pm UTC](https://discuss.google.dev/t/node-js-request-module-problem/4117/8 "2018-01-03T22:41:43Z")

</div>

no. Can you help me to figure this out?

---

<div class="post-metadata">

**Author:** ![anonymous8](https://avatars.discourse-cdn.com/v4/letter/a/7cd45c/32.png) [@anonymous8](https://discuss.google.dev/u/anonymous8)\
**Post date:** [January 3, 2018, 11:13pm UTC](https://discuss.google.dev/t/node-js-request-module-problem/4117/9 "2018-01-03T23:13:27Z")

</div>

Hi [Artem Petrosian](https://community.apigee.com/users/10780/artem-petrosian.html),

Thank you for your help.

It sounds like your right.

Do you know which version of request module I should use?

What I am trying to do is simple (call external HTTP RESTful web service).

How would you do this one, if you were doing the same thing?

I would like to use Node.js approach, and I am hoping that this option will give me more flexibility.

Thanks,

Tom

---

<div class="post-metadata">

**Author:** ![anonymous8](https://avatars.discourse-cdn.com/v4/letter/a/7cd45c/32.png) [@anonymous8](https://discuss.google.dev/u/anonymous8)\
**Post date:** [January 3, 2018, 11:25pm UTC](https://discuss.google.dev/t/node-js-request-module-problem/4117/10 "2018-01-03T23:25:58Z")

</div>

Hi , use below mentioned version for request module.

“request”: “1.x.x”

Thanks

Anil P

---

<div class="post-metadata">

**Author:** ![anonymous8](https://avatars.discourse-cdn.com/v4/letter/a/7cd45c/32.png) [@anonymous8](https://discuss.google.dev/u/anonymous8)\
**Post date:** [January 3, 2018, 11:35pm UTC](https://discuss.google.dev/t/node-js-request-module-problem/4117/11 "2018-01-03T23:35:39Z")

</div>

There are variety of different ways to call external service (Service Callout, JavaScript or Node.js). If you prefer Node way you can use build in **http** module.

[https://nodejs.org/docs/latest-v0.10.x/api/http.html#http\_http\_request\_options\_callback](https://nodejs.org/docs/latest-v0.10.x/api/http.html#http_http_request_options_callback)

or use compatible version of **request** module (see updated answer).

---

<div class="post-metadata">

**Author:** ![anonymous8](https://avatars.discourse-cdn.com/v4/letter/a/7cd45c/32.png) [@anonymous8](https://discuss.google.dev/u/anonymous8)\
**Post date:** [January 4, 2018, 12:08am UTC](https://discuss.google.dev/t/node-js-request-module-problem/4117/12 "2018-01-04T00:08:19Z")

</div>

The body you are trying to post does not appear to be Json serialized as mentioned here.

[https://github.com/request/request#requestoptions-callback](https://github.com/request/request#requestoptions-callback)

That could the problem. Is the code working on your local setup ?

---

<div class="post-metadata">

**Author:** ![anonymous8](https://avatars.discourse-cdn.com/v4/letter/a/7cd45c/32.png) [@anonymous8](https://discuss.google.dev/u/anonymous8)\
**Post date:** [January 4, 2018, 3:07am UTC](https://discuss.google.dev/t/node-js-request-module-problem/4117/13 "2018-01-04T03:07:53Z")

</div>

You may also try express .. here is a snippet.

```auto
var express = require('express');
var bodyParser = require("body-parser");
var request = require('request');

var app = express();
app.use(bodyParser.json());
app.use (function (error, req, res, next){
    res.status(400).send(error.message);
});

var router = express.Router();
app.use("/",router);

router.get('/', function(req, res){

  var _data = JSON.parse(JSON.stringify({
    resource: {
      group_name: 'testing'
    }
  }));
  
var _url = 'https://test.com/api/v2/asa';
request.post({
          headers: {'content-type': 'application/json', 'Accept-Charset': 'utf-8', 'Api-Key': '33769302e0812dsadasdadd' },
          url: _url,
          json: _data
      }, function (error, response, body) {
          if (!error) {
            console.log(body);
          }
      });

      res.send("Hello");
});

app.listen(9000);

******************************************

{
  "name": "community",
  "version": "1.0.0",
  "description": "",
  "main": "index.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "author": "",
  "license": "ISC",
  "dependencies": {
    "body-parser": "^1.18.2",
    "express": "^4.16.2"
  }
}

```
