title: Firebase.child failed: First argument was an invalid path
body: <p>Possible duplicate. Not sure.</p>
  
  <pre><code>connections: {
        connectionID : {
           userID: true,
           anotherUserID: true
        },
  
   users: {
     userID : {
         deviceToken : "tokenID",
         name : "Display Name"
     },
     anotherUserID : {
         deviceToken : "tokenID",
         name : "Display Name"
     }
   }
  </code></pre>
  
  <p>and so on and so forth.</p>
  
  <p>This is my index.js: </p>
  
  <pre><code>exports.sendConnectionNotification = functions.database.ref('/connections/{connectionID}/{userID}').onWrite(event =&gt; {
  
    const parentRef = event.data.ref.parent;
    const userID = event.params.userID;
    const connectionID = event.params.connectionID;
  
     // If un-follow we exit the function.
    if (!event.data.val()) {
      return console.log('Connection', connectionID, 'was removed.');
    }
  
    // Get the list of device notification tokens.
    const getDeviceTokensPromise = admin.database().ref('/users/${userID}/deviceToken').once('value');
  
    // Get the user profile.
    const getUserProfilePromise = admin.auth().getUser(userID);
  </code></pre>
  
  <p>and it continues. I am getting this error in my logcat:</p>
  
  <pre><code>Error: Firebase.child failed: First argument was an invalid path: "/users/${userID}/deviceToken". Paths must be non-empty strings and can't contain ".", "#", "$", "[", or "]"
      at Error (native)
      at Ge (/user_code/node_modules/firebase-admin/lib/database/database.js:111:59)
      at R.h.n (/user_code/node_modules/firebase-admin/lib/database/database.js:243:178)
      at Fd.h.gf (/user_code/node_modules/firebase-admin/lib/database/database.js:91:631)
      at exports.sendConnectionNotification.functions.database.ref.onWrite.event (/user_code/index.js:31:51)
      at /user_code/node_modules/firebase-functions/lib/cloud-functions.js:35:20
      at process._tickDomainCallback (internal/process/next_tick.js:129:7)
  </code></pre>
  
  <p>I do not understand why Firebase is not able to reach the node. Clearly, my path is valid. Where am I going wrong? Sorry, I happen to start learning Firebase Functions just today.</p>
  
  <p>**EDIT 1: ** 
  After replacing:</p>
  
  <pre><code>const getDeviceTokensPromise = admin.database().ref('/users/${userID}/deviceToken').once('value');
  </code></pre>
  
  <p>with</p>
  
  <pre><code>const getDeviceTokensPromise = admin.database().ref(`/users/${userID}/deviceToken`).once('value');
  </code></pre>
  
  <p>I have gotten a new error. My console log displays:</p>
  
  <pre><code>There are no notification tokens to send to.
  </code></pre>
  
  <p>Here is my full index.js:</p>
  
  <pre><code>    // // Create and Deploy Your First Cloud Functions
  
  
      const functions = require('firebase-functions');
      const admin = require('firebase-admin');
      admin.initializeApp(functions.config().firebase);
  
      /**
       * Triggers when a user gets a new follower and sends a notification.
       *
       * Followers add a flag to `/followers/{followedUid}/{followerUid}`.
       * Users save their device notification tokens to `/users/{followedUid}/notificationTokens/{notificationToken}`.
       */
  
      exports.sendConnectionNotification = functions.database.ref('/connections/{connectionID}/{userID}').onWrite(event =&gt; {
  
        const parentRef = event.data.ref.parent;
        const userID = event.params.userID;
        const connectionID = event.params.connectionID;
  
         // If un-follow we exit the function.
        if (!event.data.val()) {
          return console.log('Connection', connectionID, 'was removed.');
        }
  
        // Get the list of device notification tokens.
        const getDeviceTokensPromise = admin.database().ref(`/users/${userID}/deviceToken`).once('value');
  
        // Get the user profile.
        const getUserProfilePromise = admin.auth().getUser(userID);
  
         return Promise.all([getDeviceTokensPromise, getUserProfilePromise]).then(results =&gt; {
  
          const tokensSnapshot = results[0];
          const user = results[1];
  
          // Check if there are any device tokens.
          if (!tokensSnapshot.hasChildren()) {
            return console.log('There are no notification tokens to send to.');
          }
  
          console.log('There are', tokensSnapshot.numChildren(), 'tokens to send notifications to.');
          console.log('Fetched user profile', user);
  
          // Notification details.
          const payload = {
            notification: {
              title: `${user.userNickName} is here!`,
              body: 'You can now talk to each other.'
            }
          };
  
          // Listing all tokens.
          const tokens = Object.keys(tokensSnapshot.val());
  
          // Send notifications to all tokens.
          return admin.messaging().sendToDevice(tokens, payload).then(response =&gt; {
            // For each message check if there was an error.
            const tokensToRemove = [];
            response.results.forEach((result, index) =&gt; {
              const error = result.error;
              if (error) {
                console.error('Failure sending notification to', tokens[index], error);
                // Cleanup the tokens who are not registered anymore.
                if (error.code === 'messaging/invalid-registration-token' ||
                    error.code === 'messaging/registration-token-not-registered') {
                  tokensToRemove.push(tokensSnapshot.ref.child(tokens[index]).remove());
                }
              }
            });
            return Promise.all(tokensToRemove);
          });
     });
  });
  </code></pre>