天天看点

【Node.JS】写入文件内容

fs.writeFile()语法格式

fs.writeFile(filepath,data[,options],callback)

  • 参数一:必选参数,为被写入文件的路径,字符串格式
  • 参数二:必选参数,表示写入的内容。
  • 参数三:可选参数,表示以什么格式写入文件内容 默认utf-8
  • 参数四:必选参数,写入完成后的回调函数

 写入成功 err则返回 null

const fs = require('fs');//导入模块
fs.writeFile('./files/1.txt', 'node.js', function (err) {
    console.log(err);

})      
【Node.JS】写入文件内容
const fs = require('fs');//导入模块
fs.writeFile('./filesa/10.txt', 'node.js', function (err) {
    console.log(err);

})      

继续阅读