Skip to content

Instantly share code, notes, and snippets.

@sebasalvarado
Last active February 3, 2018 21:00
Show Gist options
  • Save sebasalvarado/b6369de4da9c1db5c31181f018dad691 to your computer and use it in GitHub Desktop.
Save sebasalvarado/b6369de4da9c1db5c31181f018dad691 to your computer and use it in GitHub Desktop.
Leer una file JSON
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