I have question about node.js routes. Which routing version is correct? First version it's a standard version in express.js:
router.get('/packages/:name', (req, res) => {
//my example code
);
Second version with TypeScript. This version is from typeorm init command.
export const Routes = [{
method: "post",
route: "/user",
controller: CustomerController,
action: "createUser"
}];
Which version is better and why? About the second version, how i can add custom middleware? What is difference between first and second version?
root/apiv1/[here all the routes]
then the second
one is preferable, if you have many dynamic routes, so its better to
go with the first approach.route()
end point, there we will
define the middleware just like we are doing in the first approach.