使用 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!');
});
推薦學習資源
Last updated