[Node.js]27. Level 5: URL Building & Doing the Request
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的更多相关文章
- node.js基础 1之 URL网址解析的好帮手
URL和URI的区别: URL是统一资源定位符 URI是统一资源标识符 URL是URI的子集(URL一定是URI,但URI不一定是URL) node中的URL中的url.parse protocol: ...
- node.js HTTP模块、URL 模块
在浏览器输入存在的网址的一个交互过程 1.用户通过浏览器发送一个http的请求到指定的主机 2.服务器接收到该请求,对该请求进行分析和处理 3.服务器处理完成以后,返回对应的数据到用户机器 4.浏览器 ...
- 极简 Node.js 入门 - 5.2 url & querystring
极简 Node.js 入门系列教程:https://www.yuque.com/sunluyong/node 本文更佳阅读体验:https://www.yuque.com/sunluyong/node ...
- Node.js:path、url、querystring模块
Path模块 该模块提供了对文件或目录路径处理的方法,使用require('path')引用. 1.获取文件路径最后部分basename 使用basename(path[,ext])方法来获取路径的最 ...
- [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 ...
- [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 ...
- [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 ...
- [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 ...
- [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. ...
随机推荐
- SQLSERVER2014集群实战——DNS的坑
近几日生产环境总是偶发的出现数据库连接失败的错误,一开始并未引起重视,因为反馈的人很少,而且应用服务器与数据库服务器都处在同一机房的内网环境,相互之间的访问应该是很稳定的.直到早上有几分钟的时间里出现 ...
- 【BZOJ 3456】城市规划
http://www.lydsy.com/JudgeOnline/problem.php?id=3456 设\(f(n)\)表示n个点有标号无向连通图的数目. dp:\(f(n)=2^{n\choos ...
- [USACO11DEC]Grass Planting
题目大意: 有一棵结点个数为n的树,有m个操作,可以将一段路径上每条边的权值+1或询问某一个边的权值. 思路: 树链剖分+线段树. 轻重链划分本身比较简单,主要需要思考如何用线段树维护每条链. 当x, ...
- [CodeChef-QTREE6]Query on a tree VI
题目大意: 给你一棵黑白树,每个点默认是白色,要求支持以下两种操作: 1.改变一个点的颜色: 2.除去连接不同颜色的点的边,求某个点连通块的大小. 思路: 对原树维护两个树链剖分, 一棵维护当点x为白 ...
- Nginx学习之一-惊群现象
惊群问题(thundering herd)的产生 在建立连接的时候,Nginx处于充分发挥多核CPU架构性能的考虑,使用了多个worker子进程监听相同端口的设计,这样多个子进程在accept建立新连 ...
- Clever Little Box 电缆组件 USB A 插座 至 USB B 插头
http://china.rs-online.com/web/p/usb-cable-assemblies/7244156/ 产品详细信息 USB3.0适配器 superspeed USB将提供10x ...
- mysql安装三 linux源码安装mysql5.6.22
http://blog.csdn.net/beiigang/article/details/43053803
- Hibernate中的Session缓存问题
1. Session 缓存: 1) . 在 Session 接口的实现中包括一系列的 Java 集合 , 这些 Java 集合构成了 Session 缓存 . 它用于存放 Sessi ...
- HTML中显示的文字自动换行
在html中控制自动换行 http://www.cnblogs.com/zjxbetter/articles/1323449.html eg: <table> <tr> < ...
- 基于遗传算法求解TSP问题(Java界面)
近期为做展示,改写了一个遗传算法求TSP的Java界面版,思路代码和 http://blog.csdn.net/wangqiuyun/article/details/12838903 这篇文章思路是一 ...