Skip to content
Learn Netverks

Lesson

Step 11/36 31% through track

path-fs-intro

path and fs introduction

Last reviewed May 28, 2026 Content v20260528
Track mode
nodejs_server
Means
Node sandbox
Reading
~1 min
Level
beginner

This lesson

An orientation to the Node.js track—how the server playground works, core vocabulary, and what you will practice next.

You need a clear map of the Node.js track so the event loop, modules, and server runtime do not feel like magic.

You will apply path and fs introduction in contexts like: REST/GraphQL APIs, BFF layers, CLIs, webhooks, and real-time services (with WebSockets).

Run JavaScript on the Node runner when configured—never mix arbitrary shell commands in lessons. Also read the interview prep blocks.

After HTML fundamentals and basic programming concepts—before or alongside SQL.

Server JavaScript reads configs, logs, and uploads from disk. node:path builds cross-platform paths; node:fs reads and writes files—prefer promise APIs with async/await.

path essentials

import path from 'node:path';
path.join('data', 'users', 'ada.json');
path.basename('/tmp/report.txt'); // report.txt
path.extname('photo.png'); // .png

Always join segments with path.join—never hard-code \ or / for portability.

fs promises

import { writeFile, readFile } from 'node:fs/promises';
await writeFile('note.txt', 'Hello', 'utf8');
const text = await readFile('note.txt', 'utf8');

Safety

Never pass raw user input into file paths without validation—path traversal attacks use ../ to escape intended directories.

Important interview questions and answers

  1. Q: readFileSync vs readFile?
    A: Sync blocks the event loop; async fs.promises yields during I/O—prefer async in servers.
  2. Q: path.join vs string concat?
    A: join normalizes separators and .. safely for the OS.

Self-check

  1. Why avoid sync fs in request handlers?
  2. What does path.basename return?

Interview tip Lesson completion confidence

Can you explain this lesson in 30 seconds without reading notes?

Not saved yet.

Playground

Runs on the configured server runner (dev: npm run runner with LEARNING_RUNNER_ENABLED=true). Output appears below the editor.

Check yourself

Multiple choice — immediate feedback.

Discussion

Past discussion is visible to everyone. Only logged-in users can post comments and replies.

Starter discussion topics

  • path.join vs concat?
  • Sync read risk?

Sign up or log in to post comments and sync lesson progress across devices.

No discussion yet. Be the first to ask a question.

Jump