Skip to content

Instantly share code, notes, and snippets.

@shannonjen
Created January 17, 2018 11:49
Show Gist options
  • Save shannonjen/75b65aeaf4c71cd11b3ab3564e84c0d5 to your computer and use it in GitHub Desktop.
Save shannonjen/75b65aeaf4c71cd11b3ab3564e84c0d5 to your computer and use it in GitHub Desktop.
g65 Warm Up, Wed Jan 17

User Registration

Create an Express HTTP server that contains middleware to handle POST /users requests with username and password key-value pairs in the request body. Ensure the middleware takes the following steps.

  1. Generate a hashed_password using the bcrypt cryptographic hash function.
  2. Insert the username and hashed_password into a users table.
  3. Respond with just a 200 status code on successful insertion into the table.

Be sure to pass along any errors to the error handling middleware in the stack. For good measure, include a 404 catch-all middleware in the stack as well.

As a bonus, ensure the middleware takes the following steps.

  • Respond with a 400 status code if either the username or password is blank.
  • Respond with a 400 status code if a row with the same username already exists in the users table.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment