[英]Save data to an external file
讓我們說在后端。
const htmlTxt = `
<html>
...
</html>
`
// write the file locally
fs.writeFileSync("sampleHtml.html", htmlTxt);
// read the contents of the file
console.log(fs.readFileSync("sampleHtml.html", "utf8"));
我會使用文件系統模塊。
因此,在您的 nodeJS 服務器上,您必須添加:
const fs = require('fs');
然后創建您的 json:
let jsonElement = {
aa: 'aa',
test: 123,
};
let data = JSON.stringify(jsonElement);
並將其保存到文件
fs.writeFileSync('json_file.json', data);
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.