PGoCareerGoCareer prep tools
Home
LoginSign up
  • Java
  • Python
  • AI
  • React
  • Angular
  • PHP
  • Node.js
  • SQL
  • DSA
  • HTML
  • CSS
  • JS
  • Spring
  • ML
  • MongoDB

Node.js · Theory

fs.readdirSync() Method

← All stacks

Theory

113/723

fs.readdirSync() Method

fs.readdirSync() Method sits in an upload job. Rohit’s job is read a big CSV. Write that first.

Keep fs.readdirSync() Method small. Rohit should finish read a big CSV in a few lines, not a 40-line dump.

Without fs.readdirSync() Method, an upload job gets messy and read a big CSV is hard to trust.

fs.readdirSync() Method shows up in an upload job. Name read a big CSV, not “a real-world scenario”.

fs.readdirSync() Method trap — loading the whole file into RAM. Rohit loses marks for that every viva.

fs.readdirSync() Method is not a lonely heading. Rohit ties it to read a big CSV.

Viva for fs.readdirSync() Method — what it is → createReadStream → the mistake (loading the whole file into RAM).

Exam tip

Say fs.readdirSync() Method in one breath, then createReadStream, then loading the whole file into RAM.

Example

const fs = require("fs");
const path = require("path");

const file = path.join(__dirname || ".", "demo.txt");
fs.writeFileSync(file, "hello node\n");
const text = fs.readFileSync(file, "utf8");
console.log(text.trim());
fs.unlinkSync(file);

fs.readdirSync() Method — fs reads/writes files. Prefer promises/async APIs in real apps.

Short notes

  • Deffs.readdirSync() Method — Rohit uses it for read a big CSV in an upload job.
  • Rulefs.readdirSync() Method → createReadStream.
  • Rememberfs.readdirSync() Method + the event loop (an upload job).
  • Usefs.readdirSync() Method in an upload job (read a big CSV).
  • Trapfs.readdirSync() Method — loading the whole file into RAM.
  • Exfs.readdirSync() Method → read a big CSV.

Questions

1

In one breath: what does fs.readdirSync() Method do for Rohit?

2

When would Rohit actually reach for fs.readdirSync() Method?

3

How do you catch loading the whole file into RAM?

4

Dry-run createReadStream and say the result.

Previous← fs.filehandle.truncate() methodNextprocess.unmask() →
P

GoCareerGo

Utilities · Preparation Hub · Resume · CV · Tools — one workspace.

Workspace

DashboardProfilePreparation HubResume builderCV builderCareer planning

PDF Tools

Merge PDFSplit PDFCompress PDFImage to PDFAll toolsJobs

Image & QR

Compress ImageResize ImageQR ScannerQR GeneratorBlogIT interview prep

Company

FAQFeedbackContactPrivacyTermsSitemap

© 2026 GoCareerGo. Keep moving forward.