UNPKG

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