title: How to send the OAuth request in Node
body: <p>I want to access the WS REST API in node.js. I have the <code>oauth_consumer_key</code> and the <code>oauth_token</code> and the API end point. The oauth_signature_method is HMAC-SHA1. </p>
  
  <p>How to send the OAuth request in Node? </p>
  
  <p>Is there a module/library to generate the request headers? What I expect is a function like: </p>
  
  <pre><code>var httprequest = createRequest(url, method, consumer_key, token);
  </code></pre>
  
  <hr>
  
  <ul>
  <li>UPDATE 10/14/2012. Adding the solution.</li>
  </ul>
  
  <p>I'm using the code below.</p>
  
  <pre><code>var OAuth = require('oauth').OAuth;
  
  consumer = new OAuth('http://term.ie/oauth/example/request_token.php',
                      'http://term.ie/oauth/example/access_token.php',
                      'key', 'secret', '1.0',
                      null, 'HMAC-SHA1');
  
  // Get the request token                    
  consumer.getOAuthRequestToken(function(err, oauth_token, oauth_token_secret, results ){
      console.log('==&gt;Get the request token');
      console.log(arguments);
  });
  
  
  // Get the authorized access_token with the un-authorized one.
  consumer.getOAuthAccessToken('requestkey', 'requestsecret', function (err, oauth_token, oauth_token_secret, results){
      console.log('==&gt;Get the access token');
      console.log(arguments);
  });
  
  // Access the protected resource with access token
  var url='http://term.ie/oauth/example/echo_api.php?method=foo&amp;bar=baz';
  consumer.get(url,'accesskey', 'accesssecret', function (err, data, response){
      console.log('==&gt;Access the protected resource with access token');
      console.log(err);
      console.log(data);
  });
  </code></pre>