-
Notifications
You must be signed in to change notification settings - Fork 24
/
Copy pathupload-data.js
52 lines (46 loc) · 1.1 KB
/
upload-data.js
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
41
42
43
44
45
46
47
48
49
50
51
52
// upload sample data to backend
const request = require('request')
const FIREBASE_URL = require('./src/config/api').FIREBASE_URL
const notes = [
{
title: 'Day 1',
text: 'Today is the first day of our training',
},
{
title: 'Day 2',
text: 'We started programming in JavaScript',
},
{
title: 'Day 3 - JavaScript is awesome',
text: 'Today we created our first React App - JavaScript is awesome!!!',
},
]
request(
{
method: 'PUT',
uri: `${FIREBASE_URL}.json`,
body: JSON.stringify({}),
},
(delErr, delResponse, delBody) => {
if (delErr) {
console.error('An error occurred during upload', delErr)
}
console.log(`Deleting result: ${delBody}`)
notes.map(note => {
request(
{
uri: `${FIREBASE_URL}/notes.json`,
method: 'POST',
body: JSON.stringify(note),
timeout: 10000,
},
(error, response, body) => {
if (error) {
console.error('An error occurred during upload', error)
}
console.log(`Insert result: ${body}`)
}
)
})
}
)