我有以下脚本:同步GET请求
var request = require("request");
var slogans = request.get("https://raw.githubusercontent.com/queatech/slogans/master/slogans.txt", function(err, res, body){
if (!err && res.statusCode == 200) {
return body.split("\n").splice(-1);
}
});
console.log(slogans);
我希望脚本的输出为
[ '终极Q &网站',“自由Q &一Site','The Idea Q & A Site']
但是,我得到了长的JSON GET查询。有没有办法将变量slogans
设置为https://raw.githubusercontent.com/queatech/slogans/master/slogans.txt的GET请求?
这可能吗?
恐怕这并没有解决我的问题。我想知道,我怎样才能将'slogans'变量设置为[this](https://raw.githubusercontent.com/queatech/slogans/master/slogans.txt)页面的字符“\ n “在GET请求中? – baranskistad
如果你真的想保持你的代码行在这个形状,你可以看看异步等待。 – FaureHu