Skip to content

Commit

Permalink
initial npm checkin module. nko2#104
Browse files Browse the repository at this point in the history
  • Loading branch information
Visnu Pitiyanuvath committed Aug 14, 2011
1 parent 5d0ee6b commit 4444a25
Show file tree
Hide file tree
Showing 3 changed files with 108 additions and 0 deletions.
46 changes: 46 additions & 0 deletions module/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
# node.js knockout deploy check-ins

So, we need to keep track of your deploys for lots of different reasons.
Because we want to be as deploy-agnostic as possible, we now have this fancy
module that will ping the competition website whenever you deploy.

## Installation

Add `nko` to the dependencies section of your package.json:

"dependencies": {
"nko": "*",
"other-awesome-stuff": "2.1.4"
}

After that, `npm install`.

## Usage

Just require it somewhere in your normal execution path. We recommend at the
top of your `server.js`:

require('nko')('secretc0deZ');

The code parameter is available on [your team page]. It's linked to just your
team, so don't share it with others unless you want them hijacking your
deploys.

If for whatever reason, you want to know when we've recorded the deploy, you
can pass an optional callback as the second parameter.

__Important: The module will only ping us if the `NODE_ENV` environment
variable is set to `production`.__ If you're not seeing your deploy get
recorded, make sure it's set correctly. Also, if you happen to have `NODE_ENV`
set to `production` on your development machine, no worries: we'll be making
sure the source IP address looks right before recording a deploy.

## Problems?

As always, you can contact us at [all@nodeknockout.com] or [@node_knockout].
You can also try checking the [issue tracker].

[your team page]: http://nodeknockout.com/teams/mine
[all@nodeknockout.com]: mailto:all@nodeknockout.com
[@node_knockout]: http://twitter.com/node_knockout
[issue tracker]: https://github.com/nko2/website/issues
34 changes: 34 additions & 0 deletions module/nko.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
var http = require('http'),
qs = require('querystring'),
os = require('os');

function ping(code, callback) {
if (typeof code !== 'string') {
throw Error('Go to http://nodeknockout.com/teams/mine to get your code.');
}
var options = {
host: 'nodeknockout.com',
port: 80,
path: '/teams/' + qs.escape(code) + '/deploys',
method: 'GET'
},
msg = {
hostname: os.hostname(),
os: os.type()
},

req = http.request(options);
req.setHeader('Content-Type', 'application/json');
req.end(JSON.stringify(msg));

if (callback) {
req.on('response', function (res) {
callback(null, res);
});
req.on('error', function (err) {
callback(err);
});
}
}

module.exports = ping;
28 changes: 28 additions & 0 deletions module/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
{
"name": "nko",
"maintainers": "visnup <visnupx@gmail.com>",
"author": "Danny Coates <dannycoates@gmail.com>",
"description": "node.js knockout deploy check-in",
"version": "0.0.1",
"homepage": "http://nodeknockout.com",
"repository": {
"type": "git",
"url": "git://github.com/nko2/website.git"
},
"homepage": "https://github.com/nko2/website/tree/master/module",
"keywords": [ "node.js knockout", "knockout", "nko" ],
"bugs" {
"email": "all@nodeknockout.com",
"url": "https://github.com/nko2/website/issues"
},
"contributors": [
"Danny Coates <dannycoates@gmail.com>",
"Visnu Pitiyanuvath <visnupx@gmail.com> (http://visnup.com/)"
]
"main": "nko",
"engines": {
"node": "~v0.4.10"
},
"dependencies": {},
"devDependencies": {}
}

0 comments on commit 4444a25

Please sign in to comment.