index.js
function createFileResponseHandler (options) {
	const cfg = createConfiguration(options);

	if (cfg instanceof Error) {
		return cfg;
	}

	/**
	 * @private
	 * @param {!external:"http.IncomingMessage"} req
	 * @param {!external:"http.ServerResponse"}  res
	 * @param {Function}                         [callback]   called AFTER response is finished
	 */
	function serve (req, res, callback) {
		if (callback && callback instanceof Function) {
			res.once('finish', callback);
		}

		const filePath = cfg.getFilePath(cfg, req);

		prepareFileResponse(cfg, filePath, req.headers, (err, data) => {
			if (err) {
				data = {
					statusCode: HTTP_CODES.NOT_FOUND
				};
			}

			serveFileResponse(cfg, data, res);
		});
	}

	return serve;
}
function createFileResponseHandler (options) {
	const cfg = createConfiguration(options);

	if (cfg instanceof Error) {
		return cfg;
	}

	/**
	 * @private
	 * @param {!external:"http.IncomingMessage"} req
	 * @param {!external:"http.ServerResponse"}  res
	 * @param {Function}                         [callback]   called AFTER response is finished
	 */
	function serve (req, res, callback) {
		if (callback && callback instanceof Function) {
			res.once('finish', callback);
		}

		const filePath = cfg.getFilePath(cfg, req);

		prepareFileResponse(cfg, filePath, req.headers, (err, data) => {
			if (err) {
				data = {
					statusCode: HTTP_CODES.NOT_FOUND
				};
			}

			serveFileResponse(cfg, data, res);
		});
	}

	return serve;
}
function createFileResponseHandler ( options ) { const cfg = createConfiguration ( options ) ; if ( cfg instanceof Error ) { return cfg ; } /**
	 * @private
	 * @param {!external:"http.IncomingMessage"} req
	 * @param {!external:"http.ServerResponse"}  res
	 * @param {Function}                         [callback]   called AFTER response is finished
	 */ function serve ( req , res , callback ) { if ( callback && callback instanceof Function ) { res . once ( 'finish' , callback ) ; } const filePath = cfg . getFilePath ( cfg , req ) ; prepareFileResponse ( cfg , filePath , req . headers , ( err , data ) => { if ( err ) { data = { statusCode : HTTP_CODES . NOT_FOUND } ; } serveFileResponse ( cfg , data , res ) ; } ) ; } return serve ; }
Create function that will handle serving files.

@example
var fileHandler = serveFiles();
var server = http.createServer(function (req, res) {
fileHandler(req, res, err => console.error(err));
});

@param {object}  [options]
@param {boolean} [options.followSymbolicLinks=false]    symbolic links will not be followed by default, i.e., they will not be served
@param {number}  [options.cacheTimeInSeconds=0]         HTTP cache will be disabled by default
@param {string}  [options.documentRoot=process.cwd()]   files outside of root path will not be served
@param {string}  [options.parsedURLName='urlParsed']    name of an optional property of a request object, which contains result of `url.parse(req.url)`
@return {Function|Error}
Create function that will handle serving files .