・fsモジュールを使う。
・fsモジュールのpromises namespaceにあるreadFileやwriteFileはawaitが使える。
・ファイルpathにホームディレクトリ"~"を使うとエラーになった。
import fs from 'fs';
const execute = async () => {
const data = await fs.promises.readFile('/path/to/sample_from.txt');
await fs.promises.writeFile('path/to/sample_to.txt', data.toString() + 'hoge')
}
const button = document.getElementById('button');
if (button) {
button.onclick = () => {
execute()
}
}