Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- app.post( "/api/users", function( req, res ) {
- var username = req.body.username;
- var password = req.body.password;
- var firstName = req.body.firstName;
- var lastName = req.body.lastName;
- var email = req.body.email;
- //Create a new instance of our model
- var newUser = new User( {
- username : username,
- password : password,
- firstName: firstName,
- lastName : lastName,
- email : email
- } );
- //Save our new user
- //I don't know what the best way would be to send a different response within the newUser.save function based on whether or not there's an error.
- //For example, if there's an error, I could do res.send( "Error" );
- //If not, I could send res.send( "Success" );
- //But the res var doesn't exist in the scope of the callback.
- newUser.save( function( err ) {
- //Something went wrong
- if( err ) {
- console.log( "Houston, we have a problem:", err );
- return false;
- }
- console.log( "Created a new user with the name: " + username );
- } );
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement