ensureSymlink(srcpath, dstpath, [type, callback])

Ensures that the symlink exists. If the directory structure does not exist, it is created.

  • srcpath <String>
  • dstpath <String>
  • type <String>
  • callback <Function>

Example:

  1. const fs = require('fs-extra')
  2. const srcpath = '/tmp/file.txt'
  3. const dstpath = '/tmp/this/path/does/not/exist/file.txt'
  4. fs.ensureSymlink(srcpath, dstpath, err => {
  5. console.log(err) // => null
  6. // symlink has now been created, including the directory it is to be placed in
  7. })
  8. // With Promises:
  9. fs.ensureSymlink(srcpath, dstpath)
  10. .then(() => {
  11. console.log('success!')
  12. })
  13. .catch(err => {
  14. console.error(err)
  15. })