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.readdir() method

← All stacks

Theory

103/723

fs.readdir() method

fs.readdir() method sits in an upload job. Kabir’s job is read a big CSV. Write that first.

Keep fs.readdir() method small. Kabir should finish read a big CSV in a few lines, not a 40-line dump.

Skip fs.readdir() method and loading the whole file into RAM shows up in an upload job.

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

Don’t do this with fs.readdir() method — loading the whole file into RAM. Interviewers spot it in ten seconds.

Place fs.readdir() method next to nearby Node.js work — createReadStream is the link.

Close fs.readdir() method with — “If I skip it, read a big CSV goes wrong like this: loading the whole file into RAM.”

Exam tip

Say fs.readdir() 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.readdir() method — fs reads/writes files. Prefer promises/async APIs in real apps.

Short notes

  • Deffs.readdir() method — Kabir uses it for read a big CSV in an upload job.
  • Rulefs.readdir() method → createReadStream.
  • Rememberfs.readdir() method + an Express route (an upload job).
  • Usefs.readdir() method in an upload job (read a big CSV).
  • Trapfs.readdir() method — loading the whole file into RAM.
  • Exfs.readdir() method → read a big CSV.

Questions

1

In one breath: what does fs.readdir() method do for Kabir?

2

Where does fs.readdir() method show up in an upload job?

3

Which mistake makes read a big CSV fail?

4

Change one input on read a big CSV. Predict the new result.

Previous← Node fs.appendFile()NextfsPromises.mkdtemp() Method →
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.