# The path Module — Node.js

Source: https://www.geekswithgeeks.com/en/nodejs/node-path

> Build file paths that work on every OS.

## Joining paths

`path.join` uses the right separator for the current OS.

```javascript
import path from "node:path";

const filePath = path.join("data", "users", "list.json");
console.log(filePath);                // data/users/list.json
console.log(path.basename(filePath)); // list.json
console.log(path.extname(filePath));  // .json
```

## __dirname in ESM

ES modules don't have `__dirname` — derive it from `import.meta.url` with `fileURLToPath`.
