auto-routes-linking v1.0.5
npm i auto-routes-linking
post = (request,response)=>{ res.send("get route for api/user") } delete = (request,response)=>{ res.send("get route for api/user") }
export = { get, post, delete } You can also create dynamic routes using the "param" syntax. For example, to create a route for "api/user/:user", you can create a folder named "user" inside the "routes/user" folder, and include an index.js file inside the "user" folder.routes -user -index.js -user -index.js Inside the index.js file, you can specify the appropriate methods for the dynamic route. For example:get = (request,response)=>{ res.send("get route for api/user/:user") }
export = { get } You can then import the module and use it to automatically generate routes:var express = require('express'); var routeLinking = require('auto-routes-linking'); const app = express()
routeLinking(app)// default prefix is "api" and default route path is "src/routes". To change this, you can specify the prefix and path as arguments: routeLinking(app,"api/v1","/routes") //or routeLinking(app,"api/v1","/anything")
app.listen(3000, function () { console.log('Example app listening on port 3000!'); });