Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Node Express dynamic route/path

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.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

Added :user_id to the route.

dynamic_path.get('/user/:user_id', (req, res) => {
  const user_id = req.params.user_id;
});
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading