app = express(); app.post('/user/register', function(req, res) { var user = req.body.user; bcrypt.genSalt(function(err, salt) { if(err === null) { bcrypt.hash(user.pwd, salt, function(err, hash) { if(err === null) { user.passHash = hash; db.saveUser(user, function(err, result) { if(err === null) { res.send('SUCCESS!'); } else { // Failed to save user res.send(err); } }); } else { // Failed to generate hash res.send(err); } }); } else { // Failed to generate salt res.send(err); } }); }); app.listen(80); var express = require('express'), bcrypt = require('bcrypt'), db = require('database'), async = require('async'), app = express(); app.post('/user/register', function(req, res) { var user = req.body.user; async.waterfall([ function(callback) { bcrypt.genSalt(callback); }, function(salt, callback) { bcrypt.hash(user.password, salt, callback); }, function(hash, callback) { user.passHash = hash; db.saveUser(user, callback); } ], function(err, result) { if(err === null) { res.send('SUCCESS!'); } else { res.send(err); } }); app.listen(80); Async.js Thursday, August 9, 12