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. codevs 1079 回家

    1079 回家 时间限制: 1 s 空间限制: 128000 KB 题目等级 : 白银 Silver 题目描述 Description 现在是晚餐时间,而母牛们在外面分散的牧场中. 农民约翰按响了电铃 ...

  2. 通过Nuget添加Mvvmlight框架发生错误

    IDE:Visual Studio 2013 场景:通过Nuget添加Mvvmlight框架 具体错误: 解决办法:删除Nuget,然后添加新版本的Nuget Package Manager 具体操作 ...

  3. BZOJ5217: [Lydsy2017省队十连测]航海舰队 FFT

    被FFT的空间卡了半天 后来发现根本不用开那么大... 首先可以把包含舰艇的那个小矩形找出来 将它一行一行连接成一个串T 其中舰艇位置为1其他位置为0 将大矩形也连成串S 其中礁石为1其他为0 两个串 ...

  4. Linux-JDK+Tomcat的安装笔记

    Linux-JDK+Tomcat的安装 一.JDK的安装 1.  使用命令uname –a查看系统的版本确定系统的位数,然后去JDK官网下载相应位数的安装程序,进行安装. 2.  使用rz命令将下载的 ...

  5. Git_标签管理

    发布一个版本时,我们通常先在版本库中打一个标签,这样,就唯一确定了打标签时刻的版本.将来无论什么时候,取某个标签的版本,就是把那个打标签的时刻的历史版本取出来.所以,标签也是版本库的一个快照. Git ...

  6. 前些日子用css画的大白

    闲来无事用css画的一个大白...其实有一些地方偷懒了用svg去画的,因为用纯几何形状组合去画变化那么复杂的曲线不太现实.但svg曲线坐标还是自己一点点调出来的,没有用工具生成. ps:点击身体的某些 ...

  7. HOWTO: Get the command line of a process(转)

    How would you get the command line of a process? Some people have suggested that you use remote thre ...

  8. CentOS7LINUX 内核调试符号安装

    yum install -y kernel-devel # debuginfo,在CentOS7中需要这样装 sudo vim /etc/yum.repos.d/CentOS-Debuginfo.re ...

  9. 吐槽Windows 8,就没见过这么烂的平板操作系统

    本文带有严重个人情感色彩,反感者慎入. CSDN 博文大赛得了个奖品,联想的平板电脑, MIIX2 8 .系统是 Windows 8 . 今天媳妇再次使用它,惹得我再次吐槽. 一句话.Windows ...

  10. 【Android开发学习46】Android平台切割PNG图片成小png图片

    功能描写叙述: 分解 assets 文件夹文件下的 PNG 图片成 各个小尺寸 PNG 图片 . 主函数运行: // 创建文件夹, 用来保存分解出来的图片 createPath("/sdca ...