OSDN Git Service

Regular updates
[twpd/master.git] / nodejs-path.md
1 ---
2 title: Node.js path API
3 category: Node.js
4 layout: 2017/sheet
5 intro: |
6   Quick reference to the [Node.js path API](https://nodejs.org/api/path.html).
7 ---
8
9 ### Functions
10
11 ```js
12 const fs = require('fs')
13
14 fs.realpath('/etc/passwd', function (err, path) {
15   path // => "/private/etc/passwd"
16 })
17 ```
18
19 ```js
20 const path = require('path')
21 dir = path.join('etc', 'passwd')
22 dir = path.resolve('/etc', 'passwd', '..', 'var')
23 ```
24
25 ```js
26 path.dirname('/etc/passwd') //      => "/etc"
27 path.basename('/etc/passwd') //     => "passwd"
28 path.basename('/etc/rc.d', '.d') // => "rc"
29 ```
30
31 ### References
32
33 - https://nodejs.org/api/path.html