-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.js
More file actions
40 lines (34 loc) · 955 Bytes
/
main.js
File metadata and controls
40 lines (34 loc) · 955 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
// get JSON file ready to be read
const readline = require('readline')
const fs = require('fs')
var rl = readline.createInterface({
input: fs.createReadStream('./data/entries-sample.json'),
crlfDelay: Infinity
})
var lineCount = 0
// get Firebase ready
const firebase = require('firebase')
const config = require('./config/firebase')
firebase.initializeApp(config)
const db = firebase.database()
// Write to Firebase
// Set sample data
// db.ref('/hello').set('world')
// DANGER: Reset everything
// db.ref('/sources').set(null)
// Add all data from JSON file to database
/*
rl.on('line', (line) => {
var data = JSON.parse(line.replace('$oid', 'oid'))
var source = data.source.toLowerCase()
data.source = source
db.ref('/sources').child(source).push(data)
lineCount += 1
console.log(lineCount, source)
})
*/
// Read to firebase
// Read sample data
db.ref('/hello').once('value').then((snapshot) => {
console.log(snapshot.val())
})