How to require plug-in module in node.js?

I'm testing a server (not done by me) using Mocha framework and SuperAgent module, however I need to test the server Ouath protocol. I find the superagent-oauth module in order to make sign request.

However, when I require the module I get the following error

TypeError: Object.keys called on non-object

My code, follows the readme in the superagent-oauth repo, and it is

var superagent = require('superagent');
var log = require('./log.js');
var Oauth = require('node-oauth');
var oauth = new Oauth({..});

require('superagent-oauth')(superagent);

Then when running the test I got the TypeError: Object.keys called on non-object.

When using superagent I just do

var superagent = require('superagent');
agent = superagent.agent();

But I don't know how to use/require the superagent-oauth module. So what's the way to do it correctly? Thank you

Added the trace

2) Login 'Username:Password' test: POST with a valid login logins into the AM with a valid login: TypeError: Object.keys called on non-object at Function.keys (native) at Request.query (/home/maldo/testingAM/node_modules/superagent-oauth/superagent-oauth.js:22:23) at Context. (/home/maldo/testingAM/loginUserPass.js:74:6) at Test.Runnable.run (/home/maldo/node_modules/mocha/lib/runnable.js:196:15) at Runner.runTest (/home/maldo/node_modules/mocha/lib/runner.js:343:10) at Runner.runTests.next (/home/maldo/node_modules/mocha/lib/runner.js:389:12) at next (/home/maldo/node_modules/mocha/lib/runner.js:269:14) at Runner.hooks (/home/maldo/node_modules/mocha/lib/runner.js:278:7) at next (/home/maldo/node_modules/mocha/lib/runner.js:226:23) at Runner.hook (/home/maldo/node_modules/mocha/lib/runner.js:246:5) at process.startup.processNextTick.process._tickCallback (node.js:244:9)

I got this trace in the file loginUserPass a couple of times always in the .query() statament of the agent. This happens when in the OauthAM.js I added superagent-ouath require.

Have you done npm install to retrieve all the module dependencies from npm? It seems like the dependencies for superagent are not available perhaps?

New dependencies are installed with (and put into package.json file) with npm install superagent --save.

That way you'll get all the dependencies that the superagent module needs.

Ran into same error message while installing vows on a new project created with npm init. This GitHub issues discussion suggested adding the following line to the package.json file for the project (i.e. the project you're trying to create, not the one you're trying to install):

 "dependencies": {}

This resolved it for me. Of course, you mentioned you have dependencies installed in your package.json, so this answer is more for others who might search for the error message.

https://github.com/stephenplusplus/grunt-bower-install/issues/9