Function: ensureLink()
Call Signature
ensureLink(
src
,dest
):Promise
<void
>
Ensures that the link exists. If the directory structure does not exist, it is created.
Parameters
src
string
dest
string
Returns
Promise
<void
>
Example
ts
import * as fs from 'fs-extra'
const srcPath = '/tmp/file.txt'
const destPath = '/tmp/this/path/does/not/exist/file.txt'
// With a callback:
fs.ensureLink(srcPath, destPath, err => {
console.log(err) // => null
// link has now been created, including the directory it is to be placed in
})
// With Promises:
fs.ensureLink(srcPath, destPath)
.then(() => {
console.log('success!')
})
.catch(err => {
console.error(err)
})
// With async/await:
async function asyncAwait () {
try {
await fs.ensureLink(srcPath, destPath)
console.log('success!')
} catch (err) {
console.error(err)
}
}
asyncAwait()
Defined in
packages/node/src/fs.ts:7
Call Signature
ensureLink(
src
,dest
,callback
):void
Ensures that the link exists. If the directory structure does not exist, it is created.
Parameters
src
string
dest
string
callback
NoParamCallback
Returns
void
Example
ts
import * as fs from 'fs-extra'
const srcPath = '/tmp/file.txt'
const destPath = '/tmp/this/path/does/not/exist/file.txt'
// With a callback:
fs.ensureLink(srcPath, destPath, err => {
console.log(err) // => null
// link has now been created, including the directory it is to be placed in
})
// With Promises:
fs.ensureLink(srcPath, destPath)
.then(() => {
console.log('success!')
})
.catch(err => {
console.error(err)
})
// With async/await:
async function asyncAwait () {
try {
await fs.ensureLink(srcPath, destPath)
console.log('success!')
} catch (err) {
console.error(err)
}
}
asyncAwait()
Defined in
packages/node/src/fs.ts:7