Skip to content

Instantly share code, notes, and snippets.

@apotox
Created May 24, 2019 15:55
Show Gist options
  • Save apotox/472e9be6585c675c89fcf1aec5438358 to your computer and use it in GitHub Desktop.
Save apotox/472e9be6585c675c89fcf1aec5438358 to your computer and use it in GitHub Desktop.
lambda function for Netlify serverless
import * as admin from 'firebase-admin';
//global.self = {fetch: require('node-fetch')}
var serviceAccount = {
//.....
}
const app = admin.initializeApp({
credential: admin.credential.cert(serviceAccount),
databaseURL: "https://marine-potion-230514.firebaseio.com",
})
exports.handler = async (event, context,)=>{
const note = event.queryStringParameters.note || "no text";
try{
let ref = await app.database().ref("notes").push().set({note})
return {
statusCode: 200,
body: `new note contains ${note}`
}
}catch(err){
return {
statusCode: 200,
body: `err ${err.message}`
}
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment