index.js
function getFileStats (cfg, filePath, callback) {
	fs.realpath(filePath, function (err, realpath) {
		// On Windows we can get different cases for the same disk letter :/.
		let checkPath = realpath;
		if (os.platform() === 'win32' && realpath) {
			checkPath = realpath.toLowerCase();
		}

		if (err || checkPath.indexOf(cfg.documentRootReal) !== 0) {
			return callback(err || new Error('Access denied'));
		}

		fs[cfg.followSymbolicLinks ? 'stat' : 'lstat'](filePath, function (err, stats) {
			if (err || !stats.isFile()) {
				return callback(err || new Error('Access denied'));
			}

			stats.path = realpath;

			callback(null, stats);
		});
	});
}
function getFileStats (cfg, filePath, callback) {
	fs.realpath(filePath, function (err, realpath) {
		// On Windows we can get different cases for the same disk letter :/.
		let checkPath = realpath;
		if (os.platform() === 'win32' && realpath) {
			checkPath = realpath.toLowerCase();
		}

		if (err || checkPath.indexOf(cfg.documentRootReal) !== 0) {
			return callback(err || new Error('Access denied'));
		}

		fs[cfg.followSymbolicLinks ? 'stat' : 'lstat'](filePath, function (err, stats) {
			if (err || !stats.isFile()) {
				return callback(err || new Error('Access denied'));
			}

			stats.path = realpath;

			callback(null, stats);
		});
	});
}
function getFileStats ( cfg , filePath , callback ) { fs . realpath ( filePath , function ( err , realpath ) { // On Windows we can get different cases for the same disk letter :/. let checkPath = realpath ; if ( os . platform ( ) === 'win32' && realpath ) { checkPath = realpath . toLowerCase ( ) ; } if ( err || checkPath . indexOf ( cfg . documentRootReal ) !== 0 ) { return callback ( err || new Error ( 'Access denied' ) ) ; } fs [ cfg . followSymbolicLinks ? 'stat' : 'lstat' ] ( filePath , function ( err , stats ) { if ( err || ! stats . isFile ( ) ) { return callback ( err || new Error ( 'Access denied' ) ) ; } stats . path = realpath ; callback ( null , stats ) ; } ) ; } ) ; }
Calls back with error or null and fs.Stats object as second parameter.
fs.Stats object is extended with `path` property.

@param {!module:serve-files~configuration} cfg
@param {!string}                           cfg.documentRootReal
@param {string}                            [cfg.followSymbolicLinks=false]
@param {!string}                           filePath
@param {@Function}                         callback
Calls back with error or null and fs . Stats object as second parameter . fs . Stats object is extended with path property .