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.
- Generate a
hashed_password
using the bcrypt cryptographic hash function. - Insert the
username
andhashed_password
into ausers
table. - 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 theusername
orpassword
is blank. - Respond with a
400
status code if a row with the sameusername
already exists in theusers
table.