Skip to content

Support Node 0.8+ by using fs.exists and fs.existsSync if exists, fallback if not #14

Closed
wants to merge 1 commit into from

3 participants

@jeffbski

Support Node 0.8+ by using fs.exists and fs.existsSync if exists,
fallback to path.exists and path.existsSync for Node 0.6 support

@jeffbski jeffbski Support Node 0.8+ by using fs.exists and fs.existsSync if exists,
fallback to path.exists and path.existsSync for Node 0.6 support
abc8383
@daxxog
daxxog commented Nov 3, 2012

with globals

var exists = (typeof fs.exists == 'function') ? fs.exists : path.exists;
var existsSync = (typeof fs.existsSync == 'function') ? fs.existsSync : path.existsSync;

or by adding support on the fly

if(typeof fs.exists != 'function') {
    fs.exists = path.exists;
}
if(typeof fs.existsSync != 'function') {
    fs.existsSync = path.existsSync;
}
@daxxog daxxog commented on the diff Nov 3, 2012
@@ -3,6 +3,10 @@ var path = require('path');
var EventEmitter = require('events').EventEmitter;
var Seq = require('seq');
+// allow exists and existsSync to work in Node 0.8+ (fs) and prior (path)
+var exists = (fs.exists) ? fs.exists : path.exists; // node 0.8 moved to fs
@daxxog
daxxog added a note Nov 3, 2012

or just drop this in

if(typeof fs.exists != 'function') {
    fs.exists = path.exists;
}
if(typeof fs.existsSync != 'function') {
    fs.existsSync = path.existsSync;
}

instead of using globals

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
@substack substack closed this Sep 14, 2013
@substack substack closed this Sep 14, 2013
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.