Skip to main content

Exercise 13

  • Create the following folder/file structure:
/ex_13
|-- index.js

index.js

  • Create a Express web server using port 3000
  • Connect to MongoDB database social with the npm package mongoose
  • Create a schema user with the following properties:
    • firstName - required, minlength of 2
    • lastName - required, minlength of 2
    • email - required, - required, minlength of 3, regex of email
    • about
    • date of birth - date - required
  • Create the following routes:
    • GET '/users'
      • Find all documents in the users collection
      • Returns an JSON array of users
    • GET '/users/:id'
      • Find one document by id in companies collection
      • Returns an JSON object of the user
    • POST '/users'
      • Creates a documents in the users collection
      • Returns an JSON object of the user
    • PUT '/users/:id'
      • Updates document with the id in the users collection
      • Returns an JSON object of the user
    • DELETE '/users/:id'
      • Deletes documents with id in the users collection
      • Returns an empty JSON object