Node fs模块同步读取写入追加

JS文件中
const fs = require("fs");
console.log("开始进入文件读取..");

//同步的写入
var data = fs.readFileSync("./public/1.html");

console.log("文件读取完成");
console.log(data);//返回二进制数组
console.log(data.toString()); //返回标签内容
//同步的写入
fs.writeFileSync("./public/1.log",str);
//同步的追加
fs.appendFileSync("./public/2.log",str);


原文地址:https://www.cnblogs.com/dianzan/p/7337190.html