0

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!

danelig
  • 373
  • 1
  • 4
  • 18
  • 1
    possible duplicate of [creating registration and login form in node.js and mongodb](http://stackoverflow.com/questions/8051631/creating-registration-and-login-form-in-node-js-and-mongodb). Plenty more resources can also be found here: [how to user registration node](http://google.com/search?q=how+to+user+registration+node). Short answer: In a Database, similar how it is in PHP. You can use MySQL in Node.js too. – laggingreflex Jun 13 '15 at 09:55
  • 1
    nodejs is modular. you need to connect the dots but it doesn't mean you need to do all by yourself. there are plenty of open source packages. if you choose to work with SQL database look for a matching library – Jossef Harush Kadouri Jun 13 '15 at 09:56

1 Answers1

1

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.
    });
  }
});