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. PHP 大神的十大优良习惯

    1.多阅读手册和源代码 没什么比阅读手册更值得强调的事了–仅仅通过阅读手册你就可以学习到很多东西,特别是很多有关于字符串和数组的函数.就在这些函数里面包括许多有用 的功能,如果你仔细阅读手册,你会经常 ...

  2. hdu 1026 bfs+记录路径

    题意:从0,0点出发到n-1,m-1点,路上的数字代表要在这个点额外待多少秒,求最短的路 递归输出路径即可 #include<cstdio> #include<iostream> ...

  3. MAIN/autoslb.py · 林語/autoslb - 码云 - 开源中国

    MAIN/autoslb.py · 林語/autoslb - 码云 - 开源中国 CloudXNS

  4. Android字体简述

    Android是一个典型的Linux内核的操作系统.在Android系统中,主要有DroidSans和DroidSerif两大字体阵营,从名字就可以看出来,前者是无衬线字体,后者是衬线字体.具体来说, ...

  5. Nginx 作为反向Proxy 的优化要点

    原文地址:http://my.oschina.net/hyperichq/blog/405421 常用优化要点 当nginx用于反向代理时,每个客户端将使用两个连接: 一个用于响应客户端的请求,另一个 ...

  6. 在Windows Phone项目中调用C语言DLL

    在Windows Phone项目中调用C语言写的DLL 最近接到一个需求,需要在WP里调用一个C语言写的DLL,并且说Android和iOS都可以,问我WP是否可以这样? 我说我调研一下,就有了下面的 ...

  7. python测试开发django-6.模板中include使用

    前言 当我们打开一个网站的时候,在打开不同的页面时候,会发现每个页面的顶部.底部内容都差不多,这样就可以把这些公共的部分,单独抽出来. 类似于python里面的函数,把公共部分写成函数,然后调用就行了 ...

  8. iptables配置实践

    前言 在大企业中防火墙角色主要交给硬件来支持,效果自然没话说只是需要增加一点点成本,但对于大多数个人或者互联网公司来说选择系统自带的iptables或者第三方云防火墙似乎是更加合适的选择,通过一些合理 ...

  9. HTTP 无状态啊无状态啊

    无状态的根本原因 根本原因是:因为,HTTP协议使用的是Socket套接字TCP连接的,每次监听到的套接字连接是不可能一个个保存起来的.(很消耗资源,假如一个人服务器只保存一个通信连接,一万个岂不是要 ...

  10. 成为Java高手的25个学习目标

    本文将告诉你学习Java需要达到的25个目标,希望能够对你的学习及找工作有所帮助.对比一下自己,你已经掌握了这25条中的多少 条了呢? 1.你需要精通面向对象分析与设计(OOA/OOD).涉及模式(G ...