function createMiddleWare (root, method = 'get') {
    const methodUrl = `/${method}`

    return function middleware (req, res, next) {
      const file = path.join(root, req.path, methodUrl)
      try {
        const data = require(file)
        const output = typeof data === 'function'
          ? data(req, res, next)
          : data

        // If data function has already called send, nothing shall be sent again.
        res.send(output)
      } catch (error) {
        res.status(404)
        res.send(`${error.message}. Create either ${file}.js or ${file}.json`)
      }
    }
  }
/**
   * Creates a middleware function for the given path and method that tries to
   * obtain a node module from disk, execute it and send the result.
   *
   * @param  {String} root   root path for file resolving.
   * @param  {String} method = 'get' extension to search.
   */
Creates a middleware function for the given path and method that tries to
obtain a node module from disk, execute it and send the result.

@param  {String} root   root path for file resolving.
@param  {String} method = 'get' extension to search.
Creates a middleware function for the given path and method that tries to obtain a node module from disk execute it and send the result . @param { String } root root path for file resolving . @param { String } method = ' get ' extension to search .
function createMiddleWare (root, method = 'get') {
    const methodUrl = `/${method}`
    return function middleware (req, res, next) {
      const file = path.join(root, req.path, methodUrl)
      try {
        const data = require(file)
        const output = typeof data === 'function'
          ? data(req, res, next)
          : data
        res.send(output)
      } catch (error) {
        res.status(404)
        res.send(`${error.message}. Create either ${file}.js or ${file}.json`)
      }
    }
  }
function createMiddleWare ( root , method = 'get' ) { const methodUrl = ` ${ method } ` return function middleware ( req , res , next ) { const file = path . join ( root , req . path , methodUrl ) try { const data = require ( file ) const output = typeof data === 'function' ? data ( req , res , next ) : data res . send ( output ) } catch ( error ) { res . status ( 404 ) res . send ( ` ${ error . message } ${ file } ${ file } ` ) } } }
Creates a middleware function for the given path and method that tries to
 obtain a node module from disk, execute it and send the result.
Creates a middleware function for the given path and method that tries to obtain a node module from disk execute it and send the result .
// If data function has already called send, nothing shall be sent again.