Can I use localhost?
I am using this repl for a test, however I want to apply it to a project. I want to know what exactly remote and local databases are. I also want to know, if someone else from another computer enters information in, and the code says to store it in localhost, can I access that. Like, when they say localhost, does that mean only I can add information to it through the web browser, or does it mean it is hosted on my computer and people can still add information to it?
so a database, in essence, is basically just a server that performs a service. you send the server a request (ex. to store data), and it does the request (actually stores data), and it returns a response (ex. data stored successfully). my answer is general to any type of server, but this absolutely applies to database servers.
it seems you are wondering what controls these 'requests' to the server? can anyone send a 'request' to the server from 'anywhere'?
this is the job of the operating system / kernel to manage. it controls who can send requests to certain servers. in order for the operating system to manage this, your server must tell the operating system the relevant information...
this is how your server tells the operating system where it can be reached:
when you start a server, you are starting a process (ex. nodejs, python). whether you use nodejs or python, you call some function that tells the operating system 'hey, i'm a server, if anyone wants to send me a request, i am available at this
host and this
for python flask this looks something like
for nodejs this looks something like
once you perform these method calls, the operating system knows that it can reach Baconman321's server at port
80 at host
but what is
0.0.0.0? back to your original question...
they are all addresses you can use to tell the operating system / kernel from where your server can be accessed from.
- by specifying
127.0.0.1, you tell the operating system that only your local computer can access the server
- by specifying
0.0.0.0, you tell the operating system that anyone (including your computer, and external computers) can access the server
for example, let's say you start your server with
app.run(host='127.0.0.1', port=80), and let's say i can reach your server by going to
baconman321.com. if i try to send a request to
baconman321.com, the request moves through the internet, and ends up at your computer. your kernel is the first to see it and says "wow, someone made a request to the sever at port
80! OHH, but the server is running on the address
127.0.0.1. this means that it should be only accessible on the local computer, not from the internet". the operating system then sends a response telling them about the error
in the exact same scenario, except if your used the address
0.0.0.0 instead, the operating system will see that your application wants to be accessed by an external computer, and will route that request to the application. the application handles the request, does the request (ex. stores data if it is a database), and returns the response to the operating system. the operating system then returns the response to the external server.
so, if you want to create a user in your (traditional) database, this is how it would work:
a user would send a request to mywebsite.com. mywebsite.com has a server (ex. python, nodejs) that responds with html to your web browser. you sign up for an account, which sends a request to their server (ex. python, nodejs), saying "please register this user". your python or nodejs server will send another separate request to the database server saying "actually store this user with this information".
oopsies, but pouchdb
but what i missed until just right now, is that you are using pouchdb, which is totally different
0.0.0.0 are less relevant here.
so if you want to create a user in a pouchdb database, this is how it would work:
a user would send a request to website.com. mywebsite.com has a server (that responds with html to y our web browser. you sign up for an account, which calls a
couchdb function, which stores the user with their information somewhere on the user's local machine.
here is some information on the docs that mention using
so... i guess your question was about couchdb this whole time oof i think i was answering the wrong question, but to actually answer your question
Like, when they localhost, does that mean only I can add information to it through the web browser, or does it mean it is hosted on my computer and people can still add information to it?
so because we are using pouchdb, it doesn't make as much sense to talk about it in terms of
127.0.0.1. pouchdb is stored on the user's computer. so if you have 100 users, you have 100 pouchdb databases. each database only stores the info of that users, and one user cannot access the information of another user. so no, it is not hosted on your computer and people cannot add information to it, if you only using pouchdb
i'm sorry for the wall of text, but i think only the last section 'actual answer' answers your question. maybe the first few parts can help with understanding of
localhost and stuff. lemmie know if you have any questions :)
@eankeen Thanks! That was really in-depth! Ok, so I am making a feedback page, and I just make it so it stores user input into a database that I can access later, no login pages. I really have a hard time learning this, so I'll just ask the question: Can I have other users store user input into a database, without having to add people to the database manually, or what exactly do I have to do? Also, if you work with PouchDB, can I have some help with that too? I am trying to add information, like have one document, and then add information to that document (in this repl, it's the test variable). I know it would be easier to add a new document, but if I add a new document, it will basically have the same name and id. Example: I make a var "test" and add it to a document, but if a user enters input, it will create a new document with the same name "test" so will the computer get mixed up? Or can I add documents with the same name? If not, then how do I make it so it adds a different name to the documents?
Localhost is an inbuilt http address that a web server on your computer can use to serve web pages/assets from. It cannot be accessed from outside your computer. Often you can use this IP address, 127.0.0.1, as well as it maps to localhost.
Read this article: https://en.wikipedia.org/wiki/Localhost