Skip to main content
100%

Gist 474c05b31ba635a5938112a1efb5e7ef

✓ Published0🌍 Public
Aalessioalex
Last edited Apr 7, 2016
Created on Apr 7, 2016

This example demonstrates reading a file from disk using Node.js’s synchronous file system APIs, specifically `fs.openSync`, `fs.readSync`, and `fs.closeSync`. It reads the first 4 KB chunk of `public/index.html` into a `Buffer`, converts that slice to a UTF-8 string, and prints it to the console. The code also includes a commented-out asynchronous equivalent using `fs.open`, `fs.read`, and `fs.close`, showing both approaches side by side.

AI-generated description

Similar vizzes