6

I have a url in the form www.a.com/users/uid, I want to get uid.

Assume a function :

exports.smartlink = functions.https.onRequest((req, res) =>

Doing req.params returns an empty array, whereas req.query.uid when the url contains query strings works.

2 Answers 2

8

If your URL is "www.a.com/users/uid", "uid" will be part of req.path. You can split that on '/' to get the uid as the last element of the array returned by split.

You can only use req.params with Cloud Functions for Firebase when you're exporting an entire Express app that defines a router that uses a placeholder for the element in the path you want to extract.

Sign up to request clarification or add additional context in comments.

Comments

-3

Alternatively, you can use express in firebase. and use req.param to get the value.

1 Comment

Please give a code example using express

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.