Ask coding questions

← Back to all posts
How to save data(Web)
EpicGamer007 (540)

Ok, SO I want to be able to create websites. But I want to create websites which can save data ON A SERVER.

I have been thinking about 2 options

  1. JSON + XMLHttpRequest
    and
  2. Node

I know that for XMLHttpRequest's, you need to find a way to host the json file. I do not know if the https://repl.it/@EpicGamer007/[Name of repl here]#Thing.json would work. My question with that s would I be able to send data and receive data from that json file.

I know that it is possible with node. But IDK how to use node for this.

If anyone can help with this, that would be great

Thanks to all answers :D

Answered by SpicedSpices (263) [earned 5 cycles]
View Answer
Commentshotnewtop
SpicedSpices (263)

Most of the time client databases are insecure, there are tools such as Firebase that can help though. The most secure database, and the easiest, would be to have a Node.JS database. Here are some options:

  • Repl.it Database: A very well suited tool specified for Repl.it, also super easy to work with and simple to setup. It also just came out of beta.
  • MongoDB: This is super secure, has been used for years, but it is very hard to work with and you will need a bit of tutorials to setup.
  • SQLite: Not much to say about this one, but it uses SQL format so you will need to turn your caps lock on.

Personally, I would use Repl.it Database just because it is specified for Repl.it and is insanely easy to setup. There are many tutorials on Repl.it such as Coder100's https://repl.it/talk/learn/Replit-DB/43305

EpicGamer007 (540)

@SpicedSpices , I have made a client in javafor repl db. Maybe I could use that cuz I have experience.. The only thing I am worried about is the 50 mb data limit..

SpicedSpices (263)

@EpicGamer007 50 megabytes should be good if it isn't a full product. Side projects and tests would probably be ideal with Repl.it's DB

EpicGamer007 (540)

@SpicedSpices , so If i was tryign to make something like a blogger, which could save users blogs and titles, etc.

Would repldb be big enough?

SpicedSpices (263)

@EpicGamer007 blogs would take a bit of data, lets say each blog post is about 1500 characters and with titles and with the other stuff it hits 2kb per post.
That would give you 25,000 blog posts, so if you are expecting at least half as many, I would get an external db, but 25,000 is a lot, so for a mini-project, it should be okay. MongoDB gives 512mb for free, but it is much harder to setup.

EpicGamer007 (540)

@SpicedSpices , oh ok I guess I will use repldb then, thanks so much!

SpicedSpices (263)

@EpicGamer007 no problem, if you need any more help with anything let me know :)

EpicGamer007 (540)

@SpicedSpices , umm after checking out Coder100's tutorial... I now realize something. IDK what half the stuff there means. Idk how

This:

(async () => {
  // Add async/await methods here.
})();

and how async works...

rediar (342)

@SpicedSpices Repldb should only be used for toy projects and also is kinda buggy sometimes
mongodb is pretty nice! ofc for more than 5 gig (I think) of storage, which is a lot for free, but after that you gotta pay, and I have to say its not saving the data in the repl
sqlite is cool and pretty sure it works on repl.it. maybe the best option? repl.it repls have storage limits too, pretty sure... also it would be publically visible, although you could encrypt it. So, I think this means mongodb has the highest storage limit with 512 MB to 5 GB?

EpicGamer007 (540)

@rediar , but according to one of the other people who answered, mongodb is hard to set up and learn..

SpicedSpices (263)

@EpicGamer007 async is just timing of statements. Basically instead of a normal

function a(){
  let b = 1;
  b++;
  return b;
}

you can make it an async function

async function a(){
  let b = 1;
  await b++;
  return b;
}

What this does is wait for the task after await, in this case b++, and will stop the function from running until that task is finished

SpicedSpices (263)

@EpicGamer007 so for repl db, it pauses until it does something with the database, and then runs again once that is done. It basically awaits something to finish before moving to the next thing

EpicGamer007 (540)

@SpicedSpices , oh ok I understand thank you!

rediar (342)

@EpicGamer007 nah mongodb isnt hard, just look at the tutorials. as long as you can copy and paste you can do it! lots and lots of examples and documentation.

EpicGamer007 (540)

@rediar , wait, so will the db be on repl?

rediar (342)

@EpicGamer007 mongodb is an external service. your sending the data to a far off mongodb server, its not inside the repl. for that crosis or sql probably...
vandesm's repl db suggestion is nice, but thats not storing it inside the repl, just displaying
tldr: no

EpicGamer007 (540)

@rediar , will i have to make an account to store it? or will i have to pay?

JDOG787 (413)

@EpicGamer007 its not too hard. here's a helpful video that I used.

EpicGamer007 (540)

@JDOG787 ,k i will check it out, but will i have to create an account for mongodb or pay money?

JDOG787 (413)

@EpicGamer007 you will need an account but you don't need to pay to get started. you get a certain amount free. I don't know what that amount is but Im sure its plenty as ive always had enough space when I ve used mongoldb

ironblockhd (369)

@SpicedSpices can confirm, i have a repl with 500 signed up users and 200 posts, it only takes up 400kb (0.8%) in total lol

EpicGamer007 (540)

@ironblockhd , oh thats good. well, i have been trying to get the db set up and i keep on failing. cna u send me link to some of your repls where you save data plez?

ironblockhd (369)

@EpicGamer007 uhm, i made my own database client lol

EpicGamer007 (540)

@ironblockhd , send link? I will take ANYTHIGN which I can study to try to learn.

EpicGamer007 (540)

@ironblockhd , k thanks a lot. I will check it out and report my findings back

Coder100 (8396)

No, it wouldn't. Don't even think about that.

Just use a normal server smh

Coder100 (8396)

Http requests of course! @EpicGamer007

ironblockhd (369)

Person: uses client based database
Hackers: "It's real free estate"

Vandesm14 (2383)

You'd need to set up a request using Node's HTTP server or use Express (a Node library) to route the request data to something like ReplDB.

EpicGamer007 (540)

@Vandesm14 , is there any alternatives to repldb? And there already is an official client for node so i would not need to do the requests myself..

Vandesm14 (2383)

@EpicGamer007 There are external ones like MongoDB, FonaDB, and others. File-based databases don't work on repl.it.

EpicGamer007 (540)

@Vandesm14 , yeah i know file based databases don't work... Are there any you recommend and are easy to learn and use?

Vandesm14 (2383)

@EpicGamer007 https://jsonbin.io/ is the best one I've seen that's easy and quick to set up.

EpicGamer007 (540)

@Vandesm14 , k i will check it out thanks!

Vandesm14 (2383)

@rediar It'd have to be an external/cloud DB as SQL counts as a file DB, which won't work on repl.it.

rediar (342)

@Vandesm14 ohhhh that sucks. btw on the discord I heard the crosis changes not persisting to file stuff is outdated, so crosis file changes mgith work for a db...

rediar (342)

use crosis (crosis is repl.it api) to append it to a json file
mark as answered if this helped you, I guess? thanks

EpicGamer007 (540)

@rediar , ... but idk how to use that...

rediar (342)

@EpicGamer007 Well, obviously not, but you could learn...

EpicGamer007 (540)

@rediar , how complex is it? Will it take time to learn?

rediar (342)

@EpicGamer007 http://crosis.turbio.repl.co/ (you will need api key also)
hmm, doesn't seem too hard to use (for this instance anyway)?
http://crosis.turbio.repl.co/services this seems like it provides a way to change file contents... but then it also says changes do not persist?
Idk, worth giving a try. Assuming this works, this is probably the only "true" way to host on the website repl thingy programatically.