fs.realpath

A backwards-compatible fs.realpath for Node v6 and above

In Node v6, the JavaScript implementation of fs.realpath was replaced with a faster (but less resilient) native implementation. That raises new and platform-specific errors and cannot handle long or excessively symlink-looping paths.

This module handles those cases by detecting the new errors and falling back to the JavaScript implementation. On versions of Node prior to v6, it has no effect.

USAGE

  1. var rp = require('fs.realpath')
  2. // async version
  3. rp.realpath(someLongAndLoopingPath, function (er, real) {
  4. // the ELOOP was handled, but it was a bit slower
  5. })
  6. // sync version
  7. var real = rp.realpathSync(someLongAndLoopingPath)
  8. // monkeypatch at your own risk!
  9. // This replaces the fs.realpath/fs.realpathSync builtins
  10. rp.monkeypatch()
  11. // un-do the monkeypatching
  12. rp.unmonkeypatch()