1.0.9 • Published 4 years ago

express-routes-file v1.0.9

Weekly downloads
1
License
Unlicense
Repository
github
Last release
4 years ago

express-routes-file continuous integration status npm version

Ever worked with rails, play framework, or some other web framework that used a 'routes' file to do the simple work of hooking up urls to code? Dislike the overly flexible nature of express routing and wish you had something like a routes file instead? This library is for you.

Usage

  1. To install run this command: npm install express-routes-file

  2. Create a file named routes in the root directory of your project:

    GET     /                 someFunction      # first: http method, second: url, third: name of handler function
    POST    /with-param/:id   anotherFunction   # feel free to add comments and blank lines too
  3. Set up your app like this:

    const express = require('express')
    const configureRoutes = require('express-routes-file')
    
    const app = express()
    
    // configureRoutes() returns an express.Router
    const routes = configureRoutes({
      someFunction: (req, res) => res.send('hello from someFunction()'),
      anotherFunction: (req, res) => res.send('hi from anotherFunction()')
    })
    
    app.use('/', routes)
    
    app.listen(3000, () => console.log('listening on port 3000'))

Working Examples

Using Plain Node.js

Using Typescript

1.0.9

4 years ago

1.0.8

4 years ago

1.0.7

4 years ago

1.0.6

4 years ago

1.0.5

4 years ago

1.0.4

4 years ago

1.0.3

4 years ago

1.0.2

4 years ago

1.0.1

4 years ago

1.0.0

4 years ago