Displaying streaming twitter on webpage with socket.io/node.js

前端 未结 2 988

I\'m trying to build a Twitter streaming web application using node.js socket.io and twit.

var express = require(\'express\')
  , app = express()
  , http = requ         


        
2条回答
  •  不要未来只要你来
    2021-02-03 15:55

    The first issue is that you are constructing a new twitter listener each time a socket connection is opened. You should move that outside of the connection event. This is likely not ideal. I'm not sure how the twitter module is handling that internally but it likely actually is creating a new connection to their API each time a websocket connects.

    On the client side you jQuery could bit a bit different. If you just wanted to add a tweet to the page each time a tweet occurs, append a new tweet to the body element with $('body').append()

    See this gist for reference.

提交回复
热议问题