-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathUserEmail.js
More file actions
49 lines (37 loc) · 1.23 KB
/
UserEmail.js
File metadata and controls
49 lines (37 loc) · 1.23 KB
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
var admin = require("firebase-admin");
var serviceAccount = require("/Users/jeeva/WebstormProjects/Platform/saving-by-coding-firebase-adminsdk-dmcsw-a7022e0d3e.json");
admin.initializeApp({
credential: admin.credential.cert(serviceAccount),
databaseURL: "https://saving-by-coding.firebaseio.com"
});
const db = admin.firestore();
const csv = require('csv-parser');
const fs = require('fs');
const fastcsv = require('fast-csv');
const results = [];
fs.createReadStream('emails.csv')
.pipe(csv())
.on('data', (data) => results.push(data))
.on('end', () => {
});
//create a function to check if there are any new emails from the DB, if they are add them to the Excel sheet
addNewEmails = async function () {
const snapshot = await db.collection('email-list').get();
snapshot.forEach((doc) => {
results.push({ //goes through DB
'First Name': doc.data().userFirstName,
'Last Name':doc.data().userLastName,
Email: doc.data().userEmail
})
});
writeToCSV();
};
writeToCSV= function(){
const ws = fs.createWriteStream("emails.csv");
fastcsv
.write(results, { headers: true })
.pipe(ws);
}
addNewEmails(function () {
writeToCSV();
});