how to use node module zip in java script?

Not applicable

I install node module with help of package.json and management API. This install node module as the zip file in the node and I am unable to use this zip in my javascript file.

And can you also help me schedule an API proxy on Apigee Edge?

management API link:

https://apidocs.apigee.com/management/apis/post/organizations/%7Borg_name%7D/apis/%7Bapi_name%7D/rev...

0 3 483
3 REPLIES 3

Here's what I suggest.

Follow the pattern of a known-working nodejs Application on Apigee Edge. For example, see this one. Then extend THAT model to add your own code and additional dependencies.

When you add a new dependency, redeploy the API Proxy in its entirety.

If you use a tool to deploy your proxy-with-nodejs, then it makes the process of update-and-redeploy automated and reliable.

For example, you can look at importAndDeploy.js as a tool to help you.

Hello Dino

thanks for replying. I have followed this link and I have complete 8 steps but when I hit the app/API, it shows me the error again:

*** Starting script *** Error: Cannot find module 'sleep' Error: Cannot find module 'sleep' at module.js:340:0 at module.js:280:0 at module.js:364:0 at require (module.js:380:0) at /organization/environment/api/hello-world.js:2:0 at module.js:456:0 at module.js:474:0 at module.js:356:0 at module.js:312:0 at module.js:497:0 at startup (trireme.js:142:0) at trireme.js:923:0 *** Starting script *** Error: Cannot find module 'sleep' Error: Cannot find module 'sleep' at module.js:340:0 at module.js:280:0 at module.js:364:0 at require (module.js:380:0) at /organization/environment/api/hello-world.js:2:0 at module.js:456:0 at module.js:474:0 at module.js:356:0 at module.js:312:0 at module.js:497:0 at startup (trireme.js:142:0) at trireme.js:923:0 *** Starting script *** Error: Cannot find module 'sleep' Error: Cannot find module 'sleep' at module.js:340:0 at module.js:280:0 at module.js:364:0 at require (module.js:380:0) at /organization/environment/api/hello-world.js:2:0 at module.js:456:0 at module.js:474:0 at module.js:356:0 at module.js:312:0 at module.js:497:0 at startup (trireme.js:142:0) at trireme.js:923:0 *** Starting script *** Error: Cannot find module 'sleep' Error: Cannot find module 'sleep' at module.js:340:0 at module.js:280:0 at module.js:364:0 at require (module.js:380:0) at /organization/environment/api/hello-world.js:2:0 at module.js:456:0 at module.js:474:0 at module.js:356:0 at module.js:312:0 at module.js:497:0 at startup (trireme.js:142:0) at trireme.js:923:0 *** Starting script *** Error: Cannot find module 'sleep' Error: Cannot find module 'sleep' at module.js:340:0 at module.js:280:0 at module.js:364:0 at require (module.js:380:0) at /organization/environment/api/hello-world.js:2:0 at module.js:456:0 at module.js:474:0 at module.js:356:0 at module.js:312:0 at module.js:497:0 at startup (trireme.js:142:0) at trireme.js:923:0 *** Starting script *** Error: Cannot find module './build/Release/node_sleep.node' Error: Cannot find module

here is my node js code:

var http = require('http'); var http = require('sleep'); console.log('node.js application starting...'); var svr = http.createServer(function(req, resp) { resp.end('Hello, World!'); }); svr.listen(9000, function() { console.log('Node HTTP server is listening'); });

and my package.json:

{"dependencies" : { "sleep": "", "http":"" } }

The error message you shared indicates the sleep module is not available.

In general, to correct a "module not available" problem, what you need to do is, insure the module is installed on the server side.

In Apigee Edge this means invoking the "npm install" command via the Management API. In practice the API call looks like this:

curl -i -X POST -d 'command=install' \
  https://api.enterprise.apigee.com/v1/o/$org/apis/$proxy/revisions/$rev/npm<br>;

Before you do that, modify your package.json to use proper hygiene and provide a specific version for the modules in question. You said yours is

{"dependencies" : { "sleep": "", "http":"" } }

That might be legal, not sure, but even if it is, I would want specific versions there. Just good hygiene.


Having said that, I'm not sure the sleep module works in Trireme. It relies on a C++ library and that may not work as it does in node v8. You can test the module yourself outside of Apigee Edge by following the instructions provided here in this article on the Trireme Launcher.

What are you really trying to do with your use of the sleep module? what's the technical use case? If you're just exploring, then I suggest checking out some other npm modules instead. Try some that don't depend on c++ extensions, like http or request or moment-timezone or etc. Lots of other options obviously.

good luck.