Relm
Relm

Reputation: 8291

Firebase Functions Express : How to get URL params with paths

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.

Upvotes: 6

Views: 3058

Answers (2)

Rahul Somasundaram
Rahul Somasundaram

Reputation: 596

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

Upvotes: -3

Doug Stevenson
Doug Stevenson

Reputation: 317760

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.

Upvotes: 8

Related Questions