Let's create a page which calls the twitter search API and displays the last few results for Code School. The first step is to construct the proper URL, which is all you need to do in this challenge.

Complete the URL options which will be sent into the the url module's format method. The URL you'll want to construct is the following:

http://search.twitter.com/search.json?q=codeschool

var url = require('url');

options = {
// add URL options here
protocol: "http",
host: 'search.twitter.com',
pathname: '/search.json',
query: {q: "codeschool"}
}; var searchURL = url.format(options);
console.log(searchURL);

Next we'll need to include the request module, use that to do a simple web request, and print the returned JSON out to the console. You'll want to check out this example in the readme.

var url = require('url');
var request = require('request'); options = {
protocol: "http:",
host: "search.twitter.com",
pathname: '/search.json',
query: { q: "codeschool"}
}; var searchURL = url.format(options);
request(searchURL, function(err, res, body){
if (!err && res.statusCode == 200) {
console.log(body) // Print the google web page.
}
});

[Node.js]27. Level 5: URL Building & Doing the Request的更多相关文章

  1. node.js基础 1之 URL网址解析的好帮手

    URL和URI的区别: URL是统一资源定位符 URI是统一资源标识符 URL是URI的子集(URL一定是URI,但URI不一定是URL) node中的URL中的url.parse protocol: ...

  2. node.js HTTP模块、URL 模块

    在浏览器输入存在的网址的一个交互过程 1.用户通过浏览器发送一个http的请求到指定的主机 2.服务器接收到该请求,对该请求进行分析和处理 3.服务器处理完成以后,返回对应的数据到用户机器 4.浏览器 ...

  3. 极简 Node.js 入门 - 5.2 url & querystring

    极简 Node.js 入门系列教程:https://www.yuque.com/sunluyong/node 本文更佳阅读体验:https://www.yuque.com/sunluyong/node ...

  4. Node.js:path、url、querystring模块

    Path模块 该模块提供了对文件或目录路径处理的方法,使用require('path')引用. 1.获取文件路径最后部分basename 使用basename(path[,ext])方法来获取路径的最 ...

  5. [Node.js]29. Level 6: Socket.io: Setting up Socket.io server-side & Client socket.io setup

    Below we've already created an express server, but we want to start building a real-time Q&A mod ...

  6. [Node.js]24. Level 5: Express, Express routes

    Create an express route that responds to GET requests at the URL /tweets that responds with the file ...

  7. [Node.js]31. Level 7: Redis coming for Node.js, Simple Redis Commands

    Let's start practicing using the redis key-value store from our node application. First require the  ...

  8. [Node.js]30. Level 6: Listen 'Question' from client, and then Answer the Question

    Clients can also answer each other questions, so let's build that feature by first listening for the ...

  9. [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. ...

随机推荐

  1. sublime插件FileHeader使用,自动的添加模板

    sublime插件FileHeader能够自动的监测创建新文件动作,自动的添加模板 下载地址:https://github.com/shiyanhui/FileHeader FileHeader能够自 ...

  2. luoguP2303 [SDOI2012]Longge的问题 化式子

    求\(\sum \limits_{i = 1}^n gcd(i, n)\) \(\sum \limits_{i = 1}^n gcd(i, n)\) \(=\sum \limits_{i = 1}^n ...

  3. Eclipse 工具下Maven 项目的快速搭建

    Eclipse 工具下Maven 项目的搭建 参考博文:https://www.cnblogs.com/iflytek/p/7096481.html 什么是Maven项目 简单来说,传统的Web项目: ...

  4. HDU 5692 Snacks bfs版本dfs序 线段树

    Snacks 题目连接: http://acm.hdu.edu.cn/showproblem.php?pid=5692 Description 百度科技园内有n个零食机,零食机之间通过n−1条路相互连 ...

  5. Codeforces Round #353 (Div. 2) D. Tree Construction 模拟

    D. Tree Construction 题目连接: http://www.codeforces.com/contest/675/problem/D Description During the pr ...

  6. 2016 UESTC Training for Data Structures 题解

    题解在下已经写过一次了,所以就不再写了,下面只有代码 题解下载(1):http://pan.baidu.com/s/1hsAUjMs 题解下载(2):http://pan.baidu.com/s/1m ...

  7. SGU 405 Totalizator

    405. Totalizator Time limit per test: 0.25 second(s)Memory limit: 65536 kilobytes input: standardout ...

  8. Caffe2(2)----Eclipse环境中使用Caffe2

    使用IDE开发深度学习的应用,可以事半功倍,Caffe2已经全面支持Python,这里介绍如何在Ubantu14.04下,利用EclipseCaffe2的二次开发或应用. 1.安装eclipse 具体 ...

  9. Redis_常见JedisConnectionException异常分析

    最近项目开发中用到了Redis, 选择了官网推荐的java client Jedis.Redis常用命令学习:http://redis.io/commandsRedis官方推荐Java客户端Jedis ...

  10. 【scrapy】使用方法概要(一)(转)

    [请初学者作为参考,不建议高手看这个浪费时间] 工作中经常会有这种需求,需要抓取互联网上的数据.笔者就经常遇到这种需求,一般情况下会临时写个抓取程序,但是每次遇到这种需求的时候,都几乎要重头写,特别是 ...