Skip to content

tonyfahrion/node-simple-module-loader

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

14 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

taskFinder

A simple lookup for node "modules" within a specific directory

The idea

The express Framework is a great piece of software, easy to use and reliable. I use the taskFinder module to lookup "tasks" within a directory, where one task is a javascript-node-module (so it has to be a .js file!). After all js files are found, the taskFinder is able to create express routes for these "tasks" and will connect these tasks within express.

What are tasks?

Each task can provide multiple methods and has to export at least 3 functions:

  • taskRoute() // returns the route string, which is to be registered within express
  • taskMethods() // returns an array of supported methods
  • one of runGetTask(req, res), runPostTask(req, res) // handles the request itself

Specify param validation

module.exports = {
  description: 'Book store module',
  routes: [
    {
      route: '/v1/book/:id',
      method: 'GET',
      call: (req, res) => { return getBook(req, res) },
      params: {
        required: {
          id: (i) => parseInt(i) > 0
        }
      }
    }
  ]
}

About

A simple lookup for node "modules" within a specific directory

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published