Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialpauloliva
7,889 PointsUser Registration and Authentication to a Database using Javascript
Hi!
I have a small project that I'm working on and I was wondering if there's a Javascript Framework that will allow me to register and authenticate users to a database like when using PHP and MySql.
Also, when the user is granted access to the site, such user will be required to upload files that will be written to the local filesystem of that server.
Can this be done with Javascript or some sort of Javascript Framework, or is it better just for me to learn PHP and do it in a normal LAMP stack? Or perhaps Ruby on Rails?
I have been searching online but the majority of results are leaning towards PHP & MySql.
Thanks a lot!
5 Answers
Elias Adams
4,263 PointsI believe that it is using Express and Mongo and Node.Js.
Casey Ydenberg
15,622 PointsSince you don't mention Node I'm going to go ahead and say no.
Essentially, any code running in your browser can changed by the user, so anything granting access to a database or performing authentication would not be secure. There is no way around that.
Node is Javascript which runs on a server, and there are plugins which perform authentication. But Node is a bit of an advanced concept and I think you'd be better of learning PHP/MySQL. It's fine to have the meat of your applicaiton running in JS and just use PHP as a simple retrieval tool.
Aaron Graham
18,033 PointsI'm pretty sure you can use javascript to authenticate against a backend server using Oauth2. It gets rather complicated though. Here is the Oauth2 spec, just in case you are interested: http://tools.ietf.org/html/rfc6749#section-1.2 Be warned, it is an incredibly technical wall of text.
Even if you were to use a frontend framework, you will still need to build the backend. Javascript in a browser can't directly save to a database on a server. You would need to use a backend language to build an API around your database. Given all these issues, my guess is that it will be much easier to learn a backend framework and just do all your authentication there. Most frameworks have classes and libraries that make this almost trivial. I am not a rails guy so I can't give you much advise there, but if you are interested in php, I would start with the Laravel class here on treehouse. It doesn't get into authentication, but it should get you started.
Elias Adams
4,263 PointsTeamtreehouse is working on a course that should be released in May.
pauloliva
7,889 PointsIs the course based on Node.Js or Meteor?
Since this question was posted about a year ago I should post an update that in fact if you use Meteor.js then the user authentication is a piece of cake.
Elias Adams
4,263 PointsI believe Node.js.