Javascript 如何在没有HTML的JS中使用Blob保存JSON文件

Javascript 如何在没有HTML的JS中使用Blob保存JSON文件,javascript,json,file,blob,Javascript,Json,File,Blob,我只想使用JS将json数据存储在特定目录中的文件中。我无法看到使用以下代码创建的文件 var jsonse = JSON.stringify(submitted); var blob = new Blob([jsonse], {type: "application/json"}); var file = new File([blob], "" + workerID + ".json") JS文档链接也就足够了。假设您没有使用web浏览器,而该浏览器无法写入您的文件系统

我只想使用JS将json数据存储在特定目录中的文件中。我无法看到使用以下代码创建的文件

    var jsonse = JSON.stringify(submitted);
    var blob = new Blob([jsonse], {type: "application/json"});
    var file = new File([blob], "" + workerID + ".json")

JS文档链接也就足够了。

假设您没有使用web浏览器,而该浏览器无法写入您的文件系统,可能还有另一个明显的问题,即安全原因

您可以将脚本的输出重定向到文件

节点yourfile.js>output_file.json

或者你可以使用


我得到了未捕获的TypeError:fs.existsSync不是一个函数
// 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!");
});