Created
April 2, 2018 12:34
-
-
Save stackdumper/b3008f98bad8ed2de90884d625c77aa5 to your computer and use it in GitHub Desktop.
Export countries to firestore document
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const fetch = require('node-fetch'); | |
const fireAdmin = require('firebase-admin'); | |
fireAdmin.initializeApp({ | |
credential: fireAdmin.credential.applicationDefault() | |
}); | |
const getCountries = () => | |
new Promise((resolve, reject) => { | |
fetch('https://restcountries.eu/rest/v2/all') | |
.then(res => res.json()) | |
.then(json => { | |
resolve(json.map(({ name }) => name)); | |
}); | |
}); | |
(async () => { | |
const firestore = fireAdmin.firestore(); | |
const countriesRef = firestore.doc('config/fighters'); | |
const countries = await getCountries(); | |
await countriesRef.update({ countries }); | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment