title: Cannot read property 'user_id' of undefined
body: <p>I want to send device to device push notification through firebase cloud functions. I am writing node.js script </p>
  
  <pre><code>exports.sendNotification = functions.database.ref('/messages/{user_id}/{rec_user_id}').onWrite((event) =&gt; {
  
  const sender_user_id = event.params.user_id;
  const receiver_user_id = event.params.rec_user_id;
  
  console.log('We have a notification from : '+ sender_user_id+  " | Receiced by " + receiver_user_id);
  
  return;
  
  });
  </code></pre>
  
  <p>After deploying function on firebase cloud i got an error</p>
  
  <pre><code>TypeError: Cannot read property 'user_id' of undefined
  </code></pre>
  
  <p>Full error log is :</p>
  
  <pre><code>TypeError: Cannot read property 'user_id' of undefined
  at exports.sendNotification.functions.database.ref.onWrite.event (/user_code/index.js:28:40)
  at Object.&lt;anonymous&gt; (/user_code/node_modules/firebase-functions/lib/cloud-functions.js:112:27)
  at next (native)
  at /user_code/node_modules/firebase-functions/lib/cloud-functions.js:28:71
  at __awaiter (/user_code/node_modules/firebase-functions/lib/cloud-functions.js:24:12)
  at cloudFunction (/user_code/node_modules/firebase-functions/lib/cloud-functions.js:82:36)
  at /var/tmp/worker/worker.js:700:26
  at process._tickDomainCallback (internal/process/next_tick.js:135:7)
  </code></pre>
  
  <p>I got an answer from <a href="https://stackoverflow.com/questions/49647170/firebase-functions-cannot-read-property-user-id-of-undefined">here</a></p>
  
  <p>It was working fine, but when i used</p>
  
  <pre><code>if(!event.data.val()){
  
  return console.log('A Notification has been deleted from the database : ', sender_user_id);
  
  }
  </code></pre>
  
  <p>Firebase log again start to give me an error message saying</p>
  
  <pre><code>Cannot read property 'val' of undefined
  </code></pre>
  
  <p>How to get rid of these errors ? 
  Thanks in advance</p>