fs.writeFile in a promise, asynchronous-synchronous stuff

前端 未结 10 1553
清歌不尽
清歌不尽 2020-11-30 22:49

I need some help with my code. I\'m new at Node.js and have a lot of trouble with it.

What I\'m trying to do:

1) Fetch a .txt with Amazon products (ASINs) ;<

10条回答
  •  陌清茗
    陌清茗 (楼主)
    2020-11-30 23:32

    const util = require('util')
    const fs = require('fs');
    
    const fs_writeFile = util.promisify(fs.writeFile)
    
    fs_writeFile('message.txt', 'Hello Node.js')
        .catch((error) => {
            console.log(error)
        });
    

提交回复
热议问题