[Node.js]28. Level 5: Express Server

Now let's create an express server which queries out for this search term and just returns the json. You'll need to do a few things:

  • Require the express module
  • Create the express server 'app'
  • On a get request to '/', pipe the request(searchURL) to the response.
  • Tell the app to listen on port 8080
var url = require('url');
var request = require('request');
var express = require('express');

options = {
  protocol: "http:",
  host: "search.twitter.com",
  pathname: '/search.json',
  query: { q: "codeschool"}
};

var searchURL = url.format(options);

var app = express.createServer();
app.get('/', function(req, response){
    request(searchURL).pipe(response);
});  
app.listen(8080);

 

posted @ 2014-07-31 17:09  Zhentiw  阅读(145)  评论(0编辑  收藏  举报