How can I implement and get a dynamic route or path with Express package? The main problem is the path is an id pass by the client and had no control over it.
const express = require('express');
const dynamic_path= express();
dynamic_path.get('/user', (req, res) => {
});
exports.v1 = functions.runWith(runtimeOpts).https.onRequest(dynamic_path);
The above will result as https://my-app.net/v1/user
and the client request will be https://my-app.net/v1/user/user_id
. I need to allow dynamic path and I need to get the value of user_id
as well for future usage.
CodePudding user response:
Added :user_id
to the route.
dynamic_path.get('/user/:user_id', (req, res) => {
const user_id = req.params.user_id;
});
CodePudding user response:
use route
https://my-app.net/v1/user/:user_id
code will be like this
dynamic_path.get("/user/:user_id" , (req, res)=>{
let user_id = req.parmas.user_id
}