Convert an array to a .json file

0

well this is my code

var miJson = JSON.stringify(miArray) ;

but I need all the data of the variable "miJson" to be in a file with the extension .json

    
asked by hubman 15.11.2016 в 14:54
source

1 answer

2
  

You can create files using the File System API

For example:

var fs = require('fs');
var file = 'miJson.json';
var data = JSON.stringify(miArray);

fs.writeFile(file, data, function(err) {
    if(err) {
        return console.log(err);
    }

    console.log("El archivo se guardo con exito!");
});
    
answered by 15.11.2016 / 15:04
source