Skip to content

Instantly share code, notes, and snippets.

@stackdumper
Created April 2, 2018 12:34
Show Gist options
  • Save stackdumper/b3008f98bad8ed2de90884d625c77aa5 to your computer and use it in GitHub Desktop.
Save stackdumper/b3008f98bad8ed2de90884d625c77aa5 to your computer and use it in GitHub Desktop.
Export countries to firestore document
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