Hey guys I am making a website from Node.js and Angular Form Entry View for new users that would be entered into a MySql database, I was wondering how you would recommend I encrypt the passwords via java script to be stored in the database and I am also wondering how I could allow the submission of a photo that would be stored as well for a user profile?
+-----------+------------+------+-----+---------+-------+ | Field | Type | Null | Key | Default | Extra | +-----------+------------+------+-----+---------+-------+ | FIRSTNAME | char(60) | NO | | NULL | | | LASTNAME | char(60) | NO | | NULL | | | EMAIL | char(244) | NO | | NULL | | | USER | char(50) | NO | PRI | NULL | | | PASSWORDS | text | NO | | NULL | | | PICTURE | mediumtext | YES | | NULL | | +-----------+------------+------+-----+---------+-------+
here is the route file being called
var express = require('express');
var router = express.Router();
/* GET home page. */
router.get('createUser', function(req, res, next) {
var fname = request.body.fName;
var lname = request.body.lName;
var email = request.body.email;
var user = request.body.userName;
var pass = request.body.Password;
var pass2 = request.body.confPassword;
});
module.exports = router;
For password storage you can use something like bcrypt hashing. You would return a session token after the user successfully logs in (use crypto::randomBytes or smthg).
For images you'd need something to handle multipart form data. I've had to use busboy for streaming files but I think you'd want something of a bit easier to work with. You'll want to store it on the filesystem instead of the database since you're using MySQL. If you'd be using PostgreSQL though it would be fine to store in the large object store.
True. I should have elaborated more, the idea behind using a query builder like that is to make use of promises, which are to few and far between with people new to node. If you start learning node with promises, you'll be happier in the end.
Also would any of you know how I could render a different .jade file by clicking on a button? I tried sending post requests but nothing, I am not sure if I understand how the www , app.js, and the routes work together to do server side control?
When I type like localhost:5000 it automatically maps and renders the jade file and sends this to the user. By default if I type localhost:5000/users it brings me to a different page, I am using express so I am not sure what I need to do to do server side calls to like a controller for example? @aghost7
When you call render it will render the given jade file with the local variables that you pass into it. For the newUserPage that you have, I think the issue might be the forward slash that is in the name (but I'm not sure).
I got rid of the forward slash but it did nothing different. I understood the render part but I am confused on how do I make a server call from the client side. I tried creating a button that does this.
function newUser(){
$.get('newU');
}
And then it makes GET requests to the server and I see them on the console so I know that part is right. My question though is how do I make a function in Node.js that can receive this message and then execute the newU.js that renders the page. It is this step in the middle I do not know how to do.
npm ERR! Linux 4.4.0-24-generic npm ERR! argv "node" "/usr/local/bin/npm" "start" npm ERR! node v0.10.25 npm ERR! npm v3.10.5 npm ERR! code ELIFECYCLE npm ERR! [email protected] start: node ./bin/www npm ERR! Exit status 8 npm ERR! npm ERR! Failed at the [email protected] start script 'node ./bin/www'. npm ERR! Make sure you have the latest version of node.js and npm installed. npm ERR! If you do, this is most likely a problem with the scrap package, npm ERR! not with npm itself. npm ERR! Tell the author that this fails on your system: npm ERR! node ./bin/www npm ERR! You can get information on how to open an issue for this project with: npm ERR! npm bugs scrap npm ERR! Or if that isn't available, you can get their info via: npm ERR! npm owner ls scrap npm ERR! There is likely additional logging output above.
npm ERR! Please include the following file with any support request: npm ERR! /home/shanedrafahl/.local/share/Trash/files/scrap/npm-debug.log