Skip to content
This repository has been archived by the owner on Feb 25, 2020. It is now read-only.

Commit

Permalink
Add some usecases
Browse files Browse the repository at this point in the history
  • Loading branch information
chrismytton committed Feb 18, 2011
1 parent 74cd8e6 commit a55f11c
Showing 1 changed file with 69 additions and 0 deletions.
69 changes: 69 additions & 0 deletions nodejs/04_usecases.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
!SLIDE bullets incremental

# Use cases

* Realtime applications
* Web crawlers/scrapers
* Proxy servers
* Bridging the client/server gap

!SLIDE

# Code please!

!SLIDE smaller

## webhooks.js

@@@javascript
// Require module from node-core
var http = require("http");

// Attach function to the exports object
exports.deliver = function(options, payload, callback) {

// Create a new http request
var req = http.request(options, function(res) {
var body = '';
res.setEncoding('utf8');

// Capture the response body
res.on('data', function (chunk) {
body += chunk;
});

res.on('end', function() {
// Return the result to the caller
callback(body);
});
});

// Send the payload to the endpoint
req.write(payload);
req.end();
};

!SLIDE smaller

## application.js

@@@javascript
// Use a relative require to load the module
var webhooks = require("./webhooks");

// Create a payload and options
var payload = {
name: "hecticjeff",
webscale: true
},
options = {
host: "hecticjeff.net",
port: 80,
path: "/notify",
method: 'POST'
};

// Use the deliver method that we exported
webhooks.deliver(options, payload, function(response) {
console.log("Webhook responded with %s", response);
});

0 comments on commit a55f11c

Please sign in to comment.