can we use sync-request module in apigee?

Hi guys, currently im on mobile so just want to know if we can use sync-request node module in edge node programs?

It is not mentioned here,

http://docs.apigee.com/api-services/content/understanding-edge-support-nodejs-modules

Solved Solved
0 2 450
1 ACCEPTED SOLUTION

As no one answered here, I have tried this and yes we can use `sync-request` module in Apigee Nodejs.

We need to create a package.json as,

{
    "name":"usergrid-node",
    "version":"0.0.0",
    "description":"description",
    "main":"name",
    "dependencies": {
        "sync-request":"2.2.0",
        "usergrid":"0.10.11"
        
    }
}

Note- First I have used `latest` for sync-request, but an error was thrown as,

Error: Sync-request requires node version 0.12 or later.  If you need to use it with an older version of node
you can `npm install sync-request@2.2.0`, which was the last version to support older versions of node.
    at doRequest (/organization/environment/api/node_modules/sync-request/index.js:15)
    at /organization/environment/api/s.js:148
    at callbacks (/node_modules/express/lib/router/index.js:164)
    at param (/node_modules/express/lib/router/index.js:138)
    at pass (/node_modules/express/lib/router/index.js:145)
    at /node_modules/express/lib/router/index.js:90
    at router (/node_modules/express/lib/router/index.js:33)
    at next (/node_modules/express/node_modules/connect/lib/proto.js:193)
    at multipart (/node_modules/express/node_modules/connect/lib/middleware/multipart.js:93)
    at /node_modules/express/node_modules/connect/lib/middleware/bodyParser.js:64
    at urlencoded (/node_modules/express/node_modules/connect/lib/middleware/urlencoded.js:38)
    at /node_modules/express/node_modules/connect/lib/middleware/bodyParser.js:62
    at /node_modules/express/node_modules/connect/lib/middleware/json.js:81
    at onEnd (/node_modules/express/node_modules/connect/node_modules/raw-body/index.js:109)
    at g (events.js:180)
    at emit (events.js:92)
    at _stream_readable.js:943
    at _tickDomainCallback (trireme.js:491)
    at _tickFromSpinner (trireme.js:422)

So that is the reason I used `2.2.0` in package.json.

I have added this module and but did not use it, because the time taken to get the response was too high and hence results in Script timeout.

Once we add the above thing, we need to install the module. This can be done through Apigee Management APIs,

Manage Node Packaged Modules

Follow the instructions there and use these commands,

command=ls Returns a list of Node.js dependencies.

command=installInstalls all dependencies for the resources/node directory.

After this you need to re-deploy your proxy.

I hope this helps someone in the future.

View solution in original post

2 REPLIES 2

As no one answered here, I have tried this and yes we can use `sync-request` module in Apigee Nodejs.

We need to create a package.json as,

{
    "name":"usergrid-node",
    "version":"0.0.0",
    "description":"description",
    "main":"name",
    "dependencies": {
        "sync-request":"2.2.0",
        "usergrid":"0.10.11"
        
    }
}

Note- First I have used `latest` for sync-request, but an error was thrown as,

Error: Sync-request requires node version 0.12 or later.  If you need to use it with an older version of node
you can `npm install sync-request@2.2.0`, which was the last version to support older versions of node.
    at doRequest (/organization/environment/api/node_modules/sync-request/index.js:15)
    at /organization/environment/api/s.js:148
    at callbacks (/node_modules/express/lib/router/index.js:164)
    at param (/node_modules/express/lib/router/index.js:138)
    at pass (/node_modules/express/lib/router/index.js:145)
    at /node_modules/express/lib/router/index.js:90
    at router (/node_modules/express/lib/router/index.js:33)
    at next (/node_modules/express/node_modules/connect/lib/proto.js:193)
    at multipart (/node_modules/express/node_modules/connect/lib/middleware/multipart.js:93)
    at /node_modules/express/node_modules/connect/lib/middleware/bodyParser.js:64
    at urlencoded (/node_modules/express/node_modules/connect/lib/middleware/urlencoded.js:38)
    at /node_modules/express/node_modules/connect/lib/middleware/bodyParser.js:62
    at /node_modules/express/node_modules/connect/lib/middleware/json.js:81
    at onEnd (/node_modules/express/node_modules/connect/node_modules/raw-body/index.js:109)
    at g (events.js:180)
    at emit (events.js:92)
    at _stream_readable.js:943
    at _tickDomainCallback (trireme.js:491)
    at _tickFromSpinner (trireme.js:422)

So that is the reason I used `2.2.0` in package.json.

I have added this module and but did not use it, because the time taken to get the response was too high and hence results in Script timeout.

Once we add the above thing, we need to install the module. This can be done through Apigee Management APIs,

Manage Node Packaged Modules

Follow the instructions there and use these commands,

command=ls Returns a list of Node.js dependencies.

command=installInstalls all dependencies for the resources/node directory.

After this you need to re-deploy your proxy.

I hope this helps someone in the future.

Absolutely it helps @Barahalikar Siddharth , Thank you for sharing solution with community. Way to go !!