Skip to content

Instantly share code, notes, and snippets.

View ujshaikh's full-sized avatar

Usman J Shaikh ujshaikh

View GitHub Profile
@ujshaikh
ujshaikh / readfile.js
Created August 11, 2024 11:00
An example of callback function with the help of fs method
const fs = require("fs");
const path = require("path")
// Resolve file path
const filePath = path.resolve("../", "data", "file.txt")
// Read file asynchronously
// 3rd params of this method is a callback function, which will return error and data
fs.readFile(filePath, "utf8", (err, data) => {
if (err) {