What is the path module in Node.js?
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.