Reputation: 11
So I'm trying to build a database that takes a form and inputs variables into a real time db, using firebase. This is the error I get:
index.html:31 Uncaught TypeError: firebase.database is not a function at index.html:31
This is the code:
function writeData() {
dbRefObject.set({
name: document.getElementById("name").value,
mail: document.getElementById("mail").value
});
}
The libraries are initialized:
<script src="https://www.gstatic.com/firebasejs/5.11.1/firebase-app.js"></script>
<script>
var firebaseConfig = {
apiKey: "AIzaSyDiiNKj-35XZWYJcYonBsjR0hGLzWZg7cs",
authDomain: "userdata-6467c.firebaseapp.com",
databaseURL: "https://userdata-6467c.firebaseio.com",
projectId: "userdata-6467c",
storageBucket: "userdata-6467c.appspot.com",
messagingSenderId: "390942612693",
appId: "1:390942612693:web:0692607d98edf2f2"
};
// Initialize Firebase
firebase.initializeApp(firebaseConfig);
Any ideas would be appreciated. Thank you!
Upvotes: 1
Views: 4462
Reputation: 545
Try read this: https://www.npmjs.com/package/firebase
In your code, you can access Firebase using:
var firebase = require('firebase');
firebase.intializeApp({
apiKey: '<your-api-key>',
authDomain: '<your-auth-domain>',
databaseURL: '<your-database-url>',
storageBucket: '<your-storage-bucket>'
});
If you setup a Service Account via Permissions in the new Google Firebase dashboard go here: https://firebase.google.com/docs/server/setup#add_the_sdk
Upvotes: 2