zl程序教程

您现在的位置是:首页 >  后端

当前栏目

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

JSserverNode 28 level Express
2023-09-14 09:00:56 时间

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);