大家下午好,我在嘗試將我的快遞服務器連接到我的Firebase數據庫時遇到了一些麻煩。我正在製作一個應用程序,它可以讓我的快遞服務器進行api調用,然後我的客戶端發送的信息就可以進行api調用this halo api.從那裏,我們從暈服務器返回給我的信息將返回給我的快遞服務器,回到我的客戶端來填充DOM。將Firebase數據庫連接到Express.js服務器時出現問題
上面所述的一切我已經開始工作了,但是現在我想要合併一個Firebase數據庫,而且事情並不是那麼完美。我想要做的是爲我的應用程序添加更多功能。因此,當我的快遞服務器(app.js
)向halo服務器發送api電話時,我想將數據發送到我的firebase數據庫,而不是發回給客戶端。對我來說,在實踐中,取而代之的是我從暈圈接收的數據對象,我現在只是稱它爲光環,因爲它更簡單,並將它發送到我的Firebase數據庫。從那裏我會使用數據庫來填充DOM。
正如我前面提到的,在實踐中,這證明要困難得多。我需要首先使用Firebase,因爲我需要爲此應用添加CRUD功能,所以不使用它是不可能的。當前運行我的服務器時,我收到此錯誤在命令行中運行後nodemon的src/app.js:
/Users/MMac/Desktop/haloApp/src/app.js:28
var dbReference = new Firebase("https://haloapp-5cfe2.firebaseio.com/");
^
TypeError: Firebase is not a function
at Object.<anonymous> (/Users/MMac/Desktop/haloApp/src/app.js:28:20)
at Module._compile (module.js:409:26)
at Object.Module._extensions..js (module.js:416:10)
at Module.load (module.js:343:32)
at Function.Module._load (module.js:300:12)
at Function.Module.runMain (module.js:441:10)
at startup (node.js:139:18)
at node.js:968:3
基於這個錯誤,我想,我並不需要提供火力點,但我正確的文件只是不知道要包括哪一個。我安裝節點包火力點,我已經閱讀教程只使用var Firebase = require("firebase");
這是我的app.js文件:
"use-strict"
var express = require("express");
//dependencies
var request = require("request");
var Options = require("./router.js")
var app = express();
var bodyParser = require("body-parser");
var Firebase = require("firebase");
Firebase.initializeApp({
databaseURL: "[databaseURL]",
serviceAccount: {
"type": "service_account",
"project_id": "haloapp-5cfe2",
"private_key_id": "[some number]",
"private_key": "[redacted]",
"client_email": "[email protected]",
"client_id": "[my client ID]",
"auth_uri": "https://accounts.google.com/o/oauth2/auth",
"token_uri": "https://accounts.google.com/o/oauth2/token",
"auth_provider_x509_cert_url": "https://www.googleapis.com/oauth2/v1/certs",
"client_x509_cert_url": "https://www.googleapis.com/robot/v1/metadata/x509/haloappservice%40haloapp-5cfe2.iam.gserviceaccount.com"
}
});
var dbReference = new Firebase("https://haloapp-5cfe2.firebaseio.com/");
而且,這裏是我的package.json文件只是櫃面:
{
"name": "haloapp",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "",
"license": "ISC",
"dependencies": {
"body-parser": "^1.15.1",
"express": "^4.13.4",
"firebase": "^3.0.5",
"nodemon": "^1.9.2"
}
}
我很欣賞任何花時間看這個問題並提供他們自己的兩分錢的人。非常感謝,讓我知道如何通過提供其他任何東西來幫助您。
您是否爲node.js創建了服務帳戶? –
@AmiHollander是的,我做到了。我傳遞給'Firebase.initializeApp({...})'的所有信息。 – m00saca
根據此鏈接:https://firebase.google.com/support/guides/firebase-web#get_a_database_reference_numbered 你錯過了兩個變量:'apiKey','authDomain' –