Created
August 30, 2011 14:22
-
-
Save codesplicer/1181006 to your computer and use it in GitHub Desktop.
Streaming twitter API + socket.io
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// SETUP | |
// Get the required modules | |
var express = require("express"), | |
mustachio = require("mustachio"), | |
sys = require("sys"), | |
app = express.createServer(); | |
// Configure the app | |
app.configure(function() { | |
app.use(express.static(__dirname + '/public')); | |
app.register('.mustache', mustachio); | |
app.set('view engine', 'mustache'); | |
}); | |
// CONFIG FOR TWITTER | |
var config = { | |
user: "", | |
password: "", | |
track: ["#nodetwitter"]}; | |
var socket = require('socket.io').listen(app), | |
twitter = new (require("twitter-node").TwitterNode)(config); | |
socket.addListener('clientMessage', function(data, client){ | |
client.sockets.send(data); | |
}); | |
.addListener('error', function(error){ // Always check for errors or they popup client side | |
console.log(error.message); | |
}) | |
.addListener('tweet', function(tweet){ // A new tweet that matches the criteria has been located | |
socket.emit('clientMessage', tweet, socket); | |
}) | |
.addListener('limit', function(limit){ // New limit has been sent from the API | |
sys.puts('LIMIT: ' + sys.inspect(limit)); | |
}) | |
.addListener('delete', function(del){ // A delete event occured | |
sys.puts('DELETE: ' + sys.inspect(del)); | |
}) | |
.addListener('end', function(resp){ // API disconnect | |
sys.puts('wave goodbye...' + resp.statusCode); | |
}) | |
.stream(); | |
// END SETUP | |
// CONTROLLERS | |
app.get("/", function(req, res){ | |
// Render the layout | |
res.render('layout', { | |
title: "Amy and Steve Wedding" | |
}); | |
}); | |
// END CONTROLLERS | |
// GO GO GO! | |
app.listen(3000); | |
console.log("HTTP Server Started"); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment