request.ref不是一个函数

Arn*_*hra 2 javascript node.js firebase firebase-realtime-database

我使用以下命令在此网站https://firebase.googleblog.com/2016/08/sending-notifications-between-android.html上运行了节点代码:

node app
Run Code Online (Sandbox Code Playgroud)

我收到以下错误:

TypeError: request.ref is not a function.
Run Code Online (Sandbox Code Playgroud)

对应于以下行:

sendNotificationToUser("username","new msg",function() {request.ref().remove();} );
Run Code Online (Sandbox Code Playgroud)

这是我的package.json文件:

{
"name": "myApp",
"version": "1.0.1",
"description": "listen for addition of msgs",
"main": "app.js",
"scripts": {
"start": "node app.js",
"monitor": "nodemon app.js",
"deploy": "gcloud app deploy"
},
"author": "my name",
"engines": {
"node": "~4.2"
},
"license": "ISC",
"dependencies": {
"firebase": "^3.2.1",
"request": "^2.74.0"
 }
}
Run Code Online (Sandbox Code Playgroud)

Fra*_*len 5

代码中确实存在一些拼写错误.我运行的实际版本使用它来删除已发送的消息:

requestSnapshot.ref.remove();
Run Code Online (Sandbox Code Playgroud)

整个listenForNotificationRequests方法(如果我在移植到博客时发生任何其他编辑错误):

function listenForNotificationRequests() {
  var requests = ref.child('notificationRequests');
  requests.on('child_added', function(requestSnapshot) {
    var request = requestSnapshot.val();
    sendNotificationToUser(
      request.username, 
      request.message,
      function() {
        requestSnapshot.ref.remove();
      }
    );
  }, function(error) {
    console.error(error);
  });
};
Run Code Online (Sandbox Code Playgroud)