What is the path module in Node.js?

Why Interviewers Ask This

This question tests conceptual clarity. Interviewers want to hear a precise, confident definition before moving to more complex Node.js topics. It also reveals how well you can explain technical ideas to non-experts.

Answer

The path module provides utilities for working with file and directory paths in a cross-platform way (Windows uses backslashes, Unix uses forward slashes). Key methods: path.join() — joins path segments together using the OS-specific separator: path.join("/users", "alice", "docs")"/users/alice/docs"; path.resolve() — resolves a sequence of paths to an absolute path; path.dirname(p) — returns the directory portion of a path; path.basename(p) — returns the filename portion; path.extname(p) — returns the file extension (".js"); path.parse(p) — returns an object with root, dir, base, name, ext; path.normalize(p) — normalizes a path (resolves .. and .). Use __dirname (current module's directory) and __filename (current module's full path) with path.join() to construct absolute paths relative to the current file.

Pro Tip

Demonstrate both theoretical understanding and practical experience. Say what it is, then give an example of how you actually used it in a Node.js codebase.