async/await - 1.编写一个async/await函数
首先引用node-fetch
库,就可以使用await来优雅地请求
const fetch = require('node-fetch')
async function getZhihuColumn(id) {
const url = `https://zhuanlan.zhihu.com/api/columns/${id}`
const response = await fetch(url)
const creator = await response.json()
console.log(`name:${creator.name}`) // name:前端之巅
console.log(`description:${creator.description}`) // description:InfoQ前端垂直专栏:紧跟前端发展,共享一线技术,万名淀粉互助,共登前端之巅!
}
getZhihuColumn('qianduanzhidian')