Last active
April 25, 2018 12:40
-
-
Save bogere/22a30c44c2564c269ea13b71bd941b91 to your computer and use it in GitHub Desktop.
Interacting with firebase using nodeJS
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
var storage = multer.diskStorage({ | |
destination: (req, file, cb) => { | |
cb(null, 'public/images/uploads') | |
}, | |
filename: (req, file, cb) => { | |
cb(null, file.fieldname + '-' + Date.now()) | |
} | |
}); | |
var upload = multer({storage: storage}); | |
//Now the multer is ready to upload the file in public/images/uploads folder | |
//cosult... https://medium.com/@bmshamsnahid/nodejs-file-upload-using-multer-3a904516f6d2 | |
app.post(/uploadFile/, function(req,res,next){ | |
/*upload.any(err, function(err,res){ | |
//get the text from the profile image username + profileImage | |
//post the username n profileImage from the uploaded file. to firebase. | |
req.body.username + imageUrl. | |
send these values to firebase. | |
}) */ | |
upload(req,res, function(err){ | |
if(err){ //// An error occurred when uploading | |
return res.json({"success": false, "message": 'Error uploading the files'}) | |
} | |
//here u access the text from the uploading the file | |
console.log('card stuff',req.body.cardId);//yeah here i can access fd details | |
var imagePath = req.files[0].path, | |
filePath = req.files[0].filename, | |
imageName = req.files[0].originalname; | |
/// req.body contains the text fields | |
} | |
}) | |
//post some values to firebase.. make sure this part in the upload callback | |
var postsRef = ref.child("posts"); | |
var newPostRef = postsRef.push(); | |
newPostRef.set({ | |
author: "gracehop", | |
title: "Announcing COBOL, a New Programming Language" | |
}); | |
// we can also chain the two calls together | |
postsRef.push().set({ | |
author: "alanisawesome", | |
title: "The Turing Machine" | |
}); | |
//for more interacting it with firebase using nodejs | |
https://howtofirebase.com/save-and-query-firebase-data-ed73fb8c6e3a | |
Saving Data to Firebase | |
There are three firebase functions that will add or modify your data: | |
var ref = firebase.database().ref('/some/path'); | |
var obj = {someAttribute: true}; | |
ref.push(obj); // Creates a new ref with a new "push key" | |
ref.set(obj); // Overwrites the path | |
ref.update(obj); // Updates only the specified attributes |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment