how can I retrieve data from Firebase in web using javascript? [closed] - javascript

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 2 years ago.
Improve this question
How can I retrieve data from Firebase and add to html page?
and, How can I open new html pages automatically to add the data I was retrieving it?
example:
I have this course from firbase:
this key I was pushing it .
and I want my website like this course :
When I click this courses I want to see all data about this course like this :
Can anyone help me ?!
I won't like this style just I want to know how can i retrieve data and add it in new html pages in the same style in all courses .

You can retrieve data from a firebase realtime database like so:
// Import Admin SDK
var admin = require("firebase-admin");
// Get a database reference to our posts
var db = admin.database();
var ref = db.ref("path/of/your/information");
// Attach an asynchronous callback to read the data at our posts reference
ref.on("value", function(snapshot) {
console.log(snapshot.val());
}, function (errorObject) {
console.log("The read failed: " + errorObject.code);
});
See Official Documentation here
Note: requires Node.js / npm

Related

How to save images from a link into a folder using javascript [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 1 year ago.
Improve this question
Im devleoping a discord bot ( discord.js) so, I want to create a command which is like -
+mask Name_Surname(Image URL) and when a user uses that cmd, the bot saves the image from the image url provided into a folder with the name provided by the user. (This is like for a signature bot)
An illustrative example for the above is provided -
The users uses a cmd .upload Name (URL) and the bot saves the image ( in .png format) to a folder which already exists with the "Name" provided by the user.
Click Here to View the example
Im pretty new to this, so what I would like is an example code for the above ^^ so that I can work it out myself. I hope someone can help me! Thanks
So, if you are using Node.js you can use request npm library.
client.on('message', message => {
if (message.content.startsWith('+mask')) {
const args = message.content.split(' ');
const imageURL = args[1];
var imageName = ""; //Image name
request(imageURL).pipe(fs.createWriteStream(imageName));
const attachment = new MessageAttachment(imageURL);
message.channel.send(attachment);
}
});
Request library docs - https://www.npmjs.com/package/request#streaming

handle data in LocalStorage [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 2 years ago.
Improve this question
If I work with tables (using react-tabele in my case), which store lot of pages of content.

When I first open first page and put that data in localStorage, then open second page and put that data to localStorage, then open third and store data in localStorage.

How should I handle it in reverse?

When I go back to second page, should I try to get data from localStorage() without sending request for those data?

Just bring it back from localStorage and render it?
If someone can give me example of using it in example similar like my case.
I saw mdn example, but they just wanted to show when you close tab you can inherit your old setup.
If I understand correctly, it's something related to caching your data in localStorage.
You can save timestamp together when you save the data to localStorage.
And when you arrive at that page again, you could check the timestamp and decide if you will send request or reuse the data in localStorage.
For example:
// when you save the data to localStorage
localStorage.setItem(KEY, JSON.stringify({
data: YOUR_DATA,
ts: Date.now()
}));
...
// when you read the data from localStorage
// here try/catch is used because JSON.parse will be error
// when the localStorage item is nothing or incorrect json string
try {
const { data, ts } = JSON.parse(localStorage.getItem(KEY));
if (Date.now() - +ts < SOME_SPECIFIC_TIMESTAMP) {
// use data
} else {
// send api
}
} catch (err) {
// send api
}
However it depends on why you save the data to localStorage.

Firebase JavaScript getting the UID and using it to write info to a real-time database [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 2 years ago.
Improve this question
I have written a simple JavaScript login/ signup for and am now trying to add Firebase so it will log in and out.
I have got up to the point where I am able to create an account, login and display the account email on the account page.
My next step would be to take the firstName and lastName from the input boxes and assign it to the users UID in a real-time database using Firebase.
After, doing some experimenting, reading the docs and debugging errors, I have managed to print the UID into the console, but when attempting to print the first and last name, I get ‘undefined’.
Please help me to be able to display the firstName and lastName in the account page.
Here is the code:
—SignUp Page https://jsfiddle.net/dq8o1tLv/1/
—Login Page https://jsfiddle.net/Lj312egr/1/
Thank.you
To get the current user UID, you must call the function onAuthStateChanged and get the UID
There is an exemple :
firebase.auth().onAuthStateChanged(function(user){
if(user){
uid = user.uid;
}
});
You can create a global variable called uid to stock the user UID
and then you can get the user infos from the database like :
firebase.database().ref(uid).once('value').then(function(snapshot){
document.getElementById('firstname').innerText = snapshot.val().firstname;
document.getElementById('lastname').innerText = snapshot.val().lastname;
});
To set the users info in database, you can use :
firebase.database().ref(uid).set({
firstname: document.getElementById('firstname').value,
lastname: document.getElementById('lastname').value
}).then(function(){
console.log('User added!');
});
I hope that my answer will be clear to you and that it will have helped you

How to call Zillow API with JavaScript? [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 4 years ago.
Improve this question
I'm new to APIs and am trying to figure out how to make a Zillow call with JavaScript, specifically the "getsearchresults".
Thanks
You'll need to use Javascript on the server-side using Node. It won't be possible to call the API on the front-end with Javascript. See this answer.
For using Node to call the Zillow API, check out the node-zillow package. Here's an example of how to use it with the GetSearchResults API call:
const Zillow = require("node-zillow")
const zillow = new Zillow('your key here')
const parameters = {
address: "2114 Bigelow Ave",
citystatezip: "Seattle, WA",
rentzestimate: false
}
zillow.get('GetSearchResults', parameters)
.then(results => {
console.log(results)
return results
})
Make sure you signup for ZWSID here: https://www.zillow.com/webservice/Registration.htm. You'll use this unique id when making the request to the API. It'll look something like this: X2-Ijdjkxlujnkd_jske2. Keep it secret, keep it safe!

save table data for each user with nodejs(can't use databases) [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 6 years ago.
Improve this question
I develop app for a course that I learn at the university.
I need to save table data for each user using nodejs.
i was thinking about creating an object that will contain each row data but i don't know how to save it at the server and how to load the data later.
can someone help me?
I am giving solution using Nodejs & mongodb. So please at first configure mongo.
User schema on user model :
var mongoose = require('mongoose')
, Schema = mongoose.Schema;
var user_schema=mongoose.Schema({
name: String,
email: {type: String, default: ""}
});
mongoose.model('User',user_schema);
In server code to create user :
var user = new User({name : "Test",email : "test#gmail.com"});
user.save(function(err,user){
if(!err){
console.log("user saved");
}
})

Categories