Last active
January 19, 2019 12:26
-
-
Save t-okushima/e35726cf1b428df656a4d3e403624f5f to your computer and use it in GitHub Desktop.
util.promisify()でcallbackスタイルの関数をpromise化 ref: https://qiita.com/t-okushima/items/fbca67541003576997cc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'use strct'; | |
const fs = require('fs'); | |
const util = require('util'); | |
const readFileAsync = util.promisify(fs.readFile); | |
const filePath = './test.txt'; | |
async function promisifyTest() { | |
try { | |
const text = await readFileAsync(filePath, {encoding : 'utf8'}); | |
console.log(text); | |
} catch (error) { | |
console.log(error); | |
} | |
} | |
promisifyTest(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'use strct'; | |
const fs = require('fs'); | |
const util = require('util'); | |
const readFileAsync = util.promisify(fs.readFile); | |
const filePath = './test.txt'; | |
async function promisifyTest() { | |
try { | |
const text = await readFileAsync(filePath, {encoding : 'utf8'}); | |
console.log(text); | |
} catch (error) { | |
console.log(error); | |
} | |
} | |
promisifyTest(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment