Skip to content

Latest commit

 

History

History
33 lines (21 loc) · 1.04 KB

File metadata and controls

33 lines (21 loc) · 1.04 KB

readFileSync(filePath, parsed)

Synchronously reads the entire file content. If parsed is true, attempts to parse the content as JSON. Useful for scripts where immediate, blocking access to file data is required.

Alias: readFileSync()

Parameters:

Example

const fs = require('fsmate');

const data = fs.readFile('example.txt');
console.log(data);

Use with second param parsed

const fs = require('fsmate');

const data = fs.readFile('package.json', true);

// File content will be parsed as JSON
console.log(data);

For the asynchronous version, see: readFile