-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathtest.js
More file actions
78 lines (59 loc) · 1.92 KB
/
Copy pathtest.js
File metadata and controls
78 lines (59 loc) · 1.92 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
var rp = require('request-promise');
// var XMLHttpRequest = require("xmlhttprequest");
var cheerio = require('cheerio'); // Basically jQuery for node.js
// var options = {
// uri: 'https://newsapi.org/v1/articles?source=the-next-web&sortBy=latest&apiKey=b506a06468994fcc9ed9f55451000921',
// transform: function (body) {
// return cheerio.load(body);
// }
// };
// rp(options)
// .then(function (err, response, body) {
// console.log(body);
// })
// .catch(function (err) {
// // Crawling failed or Cheerio choked...
// });
// console.log('Here');
// var options = {
// uri: 'https://newsapi.org/v1/articles?source=the-next-web&sortBy=latest&apiKey=b506a06468994fcc9ed9f55451000921',
// json: true // Automatically stringifies the body to JSON
// };
// myJson = rp(options).then(function (body) {
// console.log(body);
// myJson = body;
// return body;
// });
// function callback(data) {
// myJson = data;
// }
// function parse(parsedBody, callback) {
// // console.log(parsedBody);
// callback(parsedBody);
// }
// console.log(myJson);
// function foo() {
// var httpRequest = require("xmlhttprequest");
// httpRequest.open('GET', "/echo/json");
// httpRequest.send();
// return httpRequest.responseText;
// }
// var result = foo(); // always ends up being 'undefined'
var http = require('request-promise-json');
var myJson = {};
// myJson = http.get('https://newsapi.org/v1/articles?source=the-next-web&sortBy=latest&apiKey=b506a06468994fcc9ed9f55451000921');
function one(body) {
alert(body);
}
function two(body, callback) {
myJson = body;
}
// two("Here", one);
http.request({
url: 'https://newsapi.org/v1/articles?source=the-next-web&sortBy=latest&apiKey=b506a06468994fcc9ed9f55451000921',
json : true
}).then( function(body) {
console.log(body);
});
console.log('I need an adult');
console.log(myJson);