How to add version in cloud function for firebase

One way of doing is this to make your own path handler. Of course, you can use express but I chose not to use it just for this.

exports.getUsers = functions.https.onRequest((request, response) => {

   const path = request.path;               // '/getUsers/v2'

   const version = path.split('/')[2];      // ['', 'getUsers', 'v2']

   switch ( version ) {

      case 'v1': // Handle for v1; 
             break;

      case 'v2': // Handle for v2; 
             break;
   }
});

This will expose your endpoint till https://xyz.cloudfunctions.net/getUsers but for trailing versions or any other stuff in url, you can use a handler like this.


There is no built-in versioning for Cloud Functions. The closest you can get on the default URLs is writing the version into the function name: getUsers_v2.

If you're using Firebase Hosting to give friendly URLs to your Cloud Functions, you can of course map each individual function to the URL you want.