express-routes-file
v1.0.9
Published
express routing via rails / play-framework style 'routes' file
Downloads
7
Readme
express-routes-file
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
To install run this command:
npm install express-routes-file
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
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'))