Last active
February 3, 2018 21:00
-
-
Save sebasalvarado/b6369de4da9c1db5c31181f018dad691 to your computer and use it in GitHub Desktop.
Leer una file JSON
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const fs = require("fs"); | |
// Asumiendo la file se llama data.json | |
let data; | |
fs.readFile("data.json", "utf8", (err, fileData) => { | |
if (err) { | |
throw new Error("Error leyendo la file"); | |
} | |
data = JSON.parse(fileData); | |
// La variable data tiene tu file | |
}); | |
// Escribir en un file | |
fs.writeFile("nuevoFile.json", data, (err) => { | |
if (err) throw new Error("Error escribiendo en la nueva file"); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment