|
2 | 2 | // These samples are intended for Web so this import would normally be |
3 | 3 | // done in HTML however using modules here is more convenient for |
4 | 4 | // ensuring sample correctness offline. |
5 | | -var firebase = require("firebase/app"); |
6 | | -require("firebase/database"); |
| 5 | +import firebase from "firebase/app"; |
| 6 | +import "firebase/database"; |
7 | 7 |
|
8 | | -function onDocumentReady(firebase) { |
| 8 | +function onDocumentReady() { |
9 | 9 | //[START rtdb_emulator_connect] |
| 10 | + var db = firebase.database(); |
10 | 11 | if (location.hostname === "localhost") { |
11 | | - |
12 | | - var firebaseConfig = { |
13 | | - // Point to the RTDB emulator running on localhost. |
14 | | - // In almost all cases the ns (namespace) is your project ID. |
15 | | - databaseURL: "http://localhost:9000?ns=YOUR_DATABASE_NAMESPACE" |
16 | | - } |
17 | | - |
18 | | - var myApp = firebase.initializeApp(firebaseConfig); |
19 | | - var db = myApp.database(); |
| 12 | + // Point to the RTDB emulator running on localhost. |
| 13 | + db.useEmulator("localhost", 9000); |
20 | 14 | } |
21 | 15 | // [END rtdb_emulator_connect] |
22 | 16 | } |
23 | 17 |
|
24 | | -function flushRealtimeDatabase(firebase) { |
25 | | - |
| 18 | +function flushRealtimeDatabase() { |
26 | 19 | //[START rtdb_emulator_flush] |
27 | 20 | // With a database Reference, write null to clear the database. |
28 | 21 | firebase.database().ref().set(null); |
|
0 commit comments