0
I have my module in the nodejs and I would like to have a prefix so I don’t have to repeat every time the beginning:
For example, in the file route js
const db = require('../services')
const routes = (server) => {
server.get('/v1', (req, res, next) => {
res.send('Engoy the silence')
next()
})
server.get('/v1/beers', async (req, res, next) => {
try{
res.send( await db.beers().all() )
}catch(error){
res.send(error)
}
next()
})
}
module.exports = routes
I would like to set a prefix earlier in mine index js.. I tried so:
server.use('/api', function(req, res, next){
})
routes(server)
But I don’t know what else to do
How do I create a prefix?