cheatsheets/nodejs-path.md

34 lines
621 B
Markdown
Raw Permalink Normal View History

2014-10-23 19:38:50 +08:00
---
title: Node.js path API
2015-11-24 12:48:01 +08:00
category: Node.js
layout: 2017/sheet
intro: |
Quick reference to the [Node.js path API](https://nodejs.org/api/path.html).
2014-10-23 19:38:50 +08:00
---
### Functions
2014-10-23 19:38:50 +08:00
```js
const fs = require('fs')
2014-10-23 19:38:50 +08:00
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"
```
2014-10-23 19:38:50 +08:00
### References
- https://nodejs.org/api/path.html