Writing files in Node.js

前端 未结 19 2024
情歌与酒
情歌与酒 2020-11-21 11:57

I\'ve been trying to find a way to write to a file when using Node.js, but with no success. How can I do that?

19条回答
  •  余生分开走
    2020-11-21 12:26

    The answers provided are dated and a newer way to do this is:

    const fsPromises = require('fs').promises
    await fsPromises.writeFile('/path/to/file.txt', 'data to write')
    

    see documents here for more info

提交回复
热议问题