[英]How to save html field data in local json file without php and js node
[英]How to save a JSON file using Blob in JS without HTML
我只想使用JS将json数据存储在特定目录中的文件中。 我无法使用以下代码查看创建的文件。
var jsonse = JSON.stringify(submitted);
var blob = new Blob([jsonse], {type: "application/json"});
var file = new File([blob], "" + workerID + ".json")
JS文档链接也足够了。
假设您未使用出于安全原因(显然是另一个问题)而无法写入文件系统的Web浏览器。
您可以将输出从脚本重定向到文件。
node yourfile.js > output_file.json
或者,您可以使用fs模块 。
// note jsonse is the json blob
var fs = require('fs');
fs.writeFile("/tmp/test", jsonse, function(err) {
if(err) {
return console.log(err);
}
console.log("The file was saved!");
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.