1
0
mirror of https://github.com/onkelbeh/cheatsheets.git synced 2025-10-17 07:57:43 +02:00
cheatsheets/nodejs-path.md
Rico Sta. Cruz 511de900ba
Formatting updates (#2133)
- Update some sheets which have very long sections
- Remove `layout: 2017/sheet` (everything has the same layout now)
- Remove outdated sheets
2024-04-03 18:30:24 +11:00

33 lines
602 B
Markdown

---
title: Node.js path API
category: Node.js
intro: |
Quick reference to the [Node.js path API](https://nodejs.org/api/path.html).
---
### Functions
```js
const fs = require('fs')
fs.realpath('/etc/passwd', function (err, path) {
path // => "/private/etc/passwd"
})
```
```js
const path = require('path')
dir = path.join('etc', 'passwd')
dir = path.resolve('/etc', 'passwd', '..', 'var')
```
```js
path.dirname('/etc/passwd') // => "/etc"
path.basename('/etc/passwd') // => "passwd"
path.basename('/etc/rc.d', '.d') // => "rc"
```
### References
- https://nodejs.org/api/path.html