fs.writeFileSync(
`./data/xxx.json`,
JSON.stringify({}, null, "\t")
);
fs.existsSync(path.resolve(filePath, fileName))
fs.mkdirSync(filePath, { recursive: true });
// 创建文件并写入
function writeFileSync(option) {
let { filePath, fileName, jsonData = {} } = option;
fs.mkdirSync(filePath, { recursive: true });
fs.writeFileSync(
path.resolve(filePath, fileName),
JSON.stringify(jsonData, null, "\t")
);
}
node 文件操作
![](https://img-home.csdnimg.cn/images/20240711042549.png)