Where does user registration data get stored with node.js

494 Views Asked by At

I have started to explore node.js and I am wondering where user data would get stored if I wanted to create a registration form/login and logout functionality to the website.

I know that with php the form data is written and stored to the SQL database that is on my server.

What happens when I start to use node.js authentification packages. Do I still need to set up a SQL database on my server? Or does it work in a different way? Where would all the usernames, passwords and reg e-mails be stored?

Rather confused but so eager to learn node.js and make a simple working registration form.

Thanks guys!

1

There are 1 best solutions below

0
On BEST ANSWER

Form data isn't necessarily stored (not unless you've handled it to be stored).

When you submit a form, you're basically creating a HTTP request, and from a HTTP request, the server can be designed to handle the data that was send from said HTTP request...

So, lets say you made a form like this:

<form method="POST" action="/register">
  <input type="text" name="email">
  <input type="submit">
</form>

Through some magic in your browser, when you click submit, this creates a HTTP request where-ever that action parameter is pointing to.

So, we can then handle this data server-side in our NodeJS:

(Lets say we've already made a method to serve the form at // ...):

http.createServer(function(req, res){

  // ...

  if (req.method === "POST") {
    // It's a post request, so lets gather the data
    var chunks = [], data = "";
    req.on("data", function(chunk){
      chunks.push(chunk.toString());
    });

    req.on("end", function(){
      data = chunks.join();

      // Handle data here...  Save it, whatever you need.
    });
  }
});