diff --git a/README.md b/README.md index 309ea9e6..7a5940c0 100644 --- a/README.md +++ b/README.md @@ -35,6 +35,8 @@ repo.write('master', 'path/to/file', 'YOUR_NEW_CONTENTS', 'YOUR_COMMIT_MESSAGE', Not only can you can write files, you can of course read them. ```js +// Retrieve contents of a certain file (assumes UTF-8) + repo.read('master', 'path/to/file', function(err, data) { }); @@ -43,9 +45,23 @@ repo.read('master', 'path/to/file', function(err, data) { Listing all files of a repository is easy too. ```js -// Retrieve contents of a certain file (assumes UTF-8) - repo.list('master', 'path/to/file', function(err, data) { }); -``` \ No newline at end of file +``` + + +Node.js +-------------- + +To use Github.js on a node.js server, include it with require(): + +```js +var Github = require("/path/to/github.js"); + +var github = new Github({ + username: "YOU_USER", + password: "YOUR_PASSWORD", + auth: "basic" +}); +``` diff --git a/github.js b/github.js index 84113ad0..d95dedc7 100644 --- a/github.js +++ b/github.js @@ -5,10 +5,10 @@ // http://substance.io/michael/github (function() { - var Github; + var API_URL = 'https://api.github.com'; - - Github = window.Github = function(options) { + + var Github = function(options) { var username = options.username; var password = options.password; @@ -236,4 +236,18 @@ return new Github.User(); }; }; + + // Export the Github object for Node.js, with + // backwards-compatibility for the old `require()` API. If we're in + // the browser, add `Github` as a global object via a string identifier, + // for Closure Compiler "advanced" mode. + if (typeof exports !== "undefined") { + if (typeof module !== "undefined" && module.exports) { + exports = module.exports = Github; + } + exports.Github = Github; + } else { + this['Github'] = Github; + } + }).call(this); \ No newline at end of file