Exercise 11
- Create the following folder/file structure:
index.js
- Create a Express web server using port 3000
- Create the following routes:
- GET '/superheroes'
- Connect to the MongoDB with the npm package
mongodb
- Select comics database
- Find all documents in the superheroes collection
- Returns an JSON array of superheroes
- GET '/superheroes/:id'
- Connect to the MongoDB with the npm package
mongodb
- Select comics database
- Find one document by id in superheroes collection
- Returns an JSON object of the superhero
- POST '/superheroes'
- Connect to the MongoDB with the npm package
mongodb
- Select comics database
- Creates a documents in the superheroes collection
- Returns an JSON object of the superhero
- PUT '/superheroes/:id'
- Connect to the MongoDB with the npm package
mongodb
- Select comics database
- Updates document with the id in the superheroes collection
- Returns an JSON object of the superhero
- DELETE '/superheroes/:id'
- Connect to the MongoDB with the npm package
mongodb
- Select comics database
- Deletes documents with id in the superheroes collection
- Returns an empty JSON object