使用 Node.js 原生 API
示例
const fs = require('fs');
// 讀取文件
fs.readFile('/path/to/file.txt', (err, data) => {
if (err) throw err;
console.log(data);
});
// 寫入文件
fs.writeFile('/path/to/file.txt', 'Hello, world!', (err) => {
if (err) throw err;
console.log('The file has been saved!');
});
推荐学习资源
最后更新于