1 | # ensureLink(srcpath, dstpath, [callback])
|
2 |
|
3 | Ensures that the link exists. If the directory structure does not exist, it is created.
|
4 |
|
5 | - `srcpath` `<String>`
|
6 | - `dstpath` `<String>`
|
7 | - `callback` `<Function>`
|
8 |
|
9 | ## Example:
|
10 |
|
11 | ```js
|
12 | const fs = require('fs-extra')
|
13 |
|
14 | const srcpath = '/tmp/file.txt'
|
15 | const dstpath = '/tmp/this/path/does/not/exist/file.txt'
|
16 |
|
17 | // With a callback:
|
18 | fs.ensureLink(srcpath, dstpath, err => {
|
19 | console.log(err) // => null
|
20 | // link has now been created, including the directory it is to be placed in
|
21 | })
|
22 |
|
23 | // With Promises:
|
24 | fs.ensureLink(srcpath, dstpath)
|
25 | .then(() => {
|
26 | console.log('success!')
|
27 | })
|
28 | .catch(err => {
|
29 | console.error(err)
|
30 | })
|
31 |
|
32 | // With async/await:
|
33 | async function example (src, dest) {
|
34 | try {
|
35 | await fs.ensureLink(src, dest)
|
36 | console.log('success!')
|
37 | } catch (err) {
|
38 | console.error(err)
|
39 | }
|
40 | }
|
41 |
|
42 | example(srcpath, dstpath)
|
43 | ```
|