Skip to content

Commit f9eb0fa

Browse files
committed
lesson 01: first async/await function
1 parent 026b4a9 commit f9eb0fa

File tree

1 file changed

+5
-7
lines changed

1 file changed

+5
-7
lines changed

01-first-async-await-function.js

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,11 @@
11
const fetch = require('node-fetch');
22

3-
function getZhihuColumn(id) {
3+
async function getZhihuColumn(id) {
44
const url = `https://zhuanlan.zhihu.com/api/columns/${id}`;
5-
fetch(url)
6-
.then(response => response.json())
7-
.then(column => {
8-
console.log(`NAME: ${column.name}`);
9-
console.log(`INTRO: ${column.intro}`);
10-
});
5+
const response = await fetch(url);
6+
const column = await response.json();
7+
console.log(`NAME: ${column.name}`);
8+
console.log(`INTRO: ${column.intro}`);
119
}
1210

1311
getZhihuColumn('feweekly');

0 commit comments

Comments
 (0)