-
Notifications
You must be signed in to change notification settings - Fork 171
Expand file tree
/
Copy pathtest.js
More file actions
27 lines (22 loc) · 706 Bytes
/
test.js
File metadata and controls
27 lines (22 loc) · 706 Bytes
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
const fs = require('fs')
const path = require('path')
const Q = require('q')
function fn1() {
const fileName1 = path.resolve(__dirname, '../data/data1.json')
const fileName2 = path.resolve(__dirname, '../data/data2.json')
const readFilePromise = Q.denodeify(fs.readFile)
// 定义 async 函数
const readFileAsync = async function () {
const f1 = await readFilePromise(fileName1)
const f2 = await readFilePromise(fileName2)
console.log('data1.json', f1.toString())
console.log('data2.json', f2.toString())
return 'done'
}
// 执行
const result = readFileAsync()
result.then(data => {
console.log(data)
})
}
fn1()