Skip to content

Instantly share code, notes, and snippets.

@fransafu
Last active February 7, 2020 00:13
Show Gist options
  • Save fransafu/fa9e5ecb0d28968ce24a762487d9186c to your computer and use it in GitHub Desktop.
Save fransafu/fa9e5ecb0d28968ce24a762487d9186c to your computer and use it in GitHub Desktop.
[Node.js] Ejemplo de uso de modulo nativo en Node.js
/*
URL DOC: https://nodejs.org/api/fs.html
URL Ejemplo: https://nodejs.org/api/fs.html#fs_fs_writefile_file_data_options_callback
*/
// Realizamos el llamado de la Biblioteca FileSystem (fs)
const fs = require('fs');
// Agregamos el mensaje 'Hello World' en un buffer y guardamos la salida en la variable 'data'
const data = new Uint8Array(Buffer.from('Hello World!'));
// Utilizamos la funcion 'writeFile' para guardar la información en el archivo 'mi_archivo.txt'
fs.writeFile('mi_archivo.txt', data, (err) => {
// Aqui controlamos el error en caso que exista
if (err) throw err;
// Si no hay error se imprime el mensaje de confirmación
console.log('Su mensaje ha sido almacenado en mi_archivo.txt.');
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment