UNPKG

861 BMarkdownView Raw
1# ensureLink(srcpath, dstpath, [callback])
2
3Ensures 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
12const fs = require('fs-extra')
13
14const srcpath = '/tmp/file.txt'
15const dstpath = '/tmp/this/path/does/not/exist/file.txt'
16
17// With a callback:
18fs.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:
24fs.ensureLink(srcpath, dstpath)
25.then(() => {
26 console.log('success!')
27})
28.catch(err => {
29 console.error(err)
30})
31
32// With async/await:
33async 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
42example(srcpath, dstpath)
43```