logo
  • 教程列表
  • SO官方文檔
  • 藍鳥承諾
    • 將 nodeback 庫轉換為 Promises
    • 功能承諾
    • 協同程式(發生器)
    • 自動資源處置(Promise.using)
    • 執行系列
  1. StackOverflow 文件
  2. Node.js 教程
  3. 藍鳥承諾
  4. 將 nodeback 庫轉換為 Promises

將 nodeback 庫轉換為 Promises

Created: November-22, 2018

const Promise = require('bluebird'),
      fs = require('fs')

Promise.promisifyAll(fs)

// now you can use promise based methods on 'fs' with the Async suffix
fs.readFileAsync('file.txt').then(contents => {
  console.log(contents)
}).catch(err => {
  console.error('error reading', err)
})
  • 功能承諾
  • 藍鳥承諾

Copyright © 2018. All right reserved

tastones.com 备案号:鲁ICP备18045372号-1

  • 關於本站
  • 免責聲明