0% found this document useful (0 votes)
34 views6 pages

File System: Autor: Thiago Porto

The Node.js API documentation provides information on the File System module. It describes the fs.readFile and fs.writeFile methods for asynchronously reading and writing files in Node.js. Useful links are also included for additional Node.js resources.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
34 views6 pages

File System: Autor: Thiago Porto

The Node.js API documentation provides information on the File System module. It describes the fs.readFile and fs.writeFile methods for asynchronously reading and writing files in Node.js. Useful links are also included for additional Node.js resources.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 6

http://nodejs.

org/api/

File System

Autor: Thiago Porto


ReadFile
fs.readFile(filename, [options], callback)
filenameString
options Object
encoding String | Null default = null
flag String default = 'r'
callback Function
Asynchronously reads the entire contents of a file. Example:

fs.readFile('/etc/passwd', function (err, data) {


if (err) throw err;
console.log(data);
});

The callback is passed two arguments (err, data), where data is the contents of the file.
If no encoding is specified, then the raw buffer is returned.
WriteFile
fs.writeFile(filename, data, [options], callback)#
filename String
data String | Buffer
options Object
encoding String | Null default = 'utf8'
mode Number default = 438 (aka 0666 in Octal)
flag String default = 'w'
callback Function
Asynchronously writes data to a file, replacing the file if it already exists. data can be a string or a buffer.
The encoding option is ignored if data is a buffer. It defaults to 'utf8'.
Example:

fs.writeFile('message.txt', 'Hello Node', function (err) {


if (err) throw err;
console.log('It\'s saved!');
});
Links úteis
Site oficial - http://nodejs.org/
NodeBR - http://nodebr.com/
Livro pt-br - http://www.casadocodigo.com.br/products/livro-nodejs
Underground WebDev - http://udgwebdev.com/nodejs/

Node.JS BRasil - https://www.facebook.com/groups/nodejsbrasil/


Node.JS Brasil (oficial) - https://www.facebook.com/groups/149291518502527/
facebook.com/WaibTecnologia

github.com/tporto

@WaibTecnologia

youtube.com/waibtecnologia

facebook.com/groups/WaibTecnologia/
Site: waib.com.br / Blog: waib.com.br/Blog
Obrigado!

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy