Skip to content

AustinCodingAcademy/advanced-express-practice

Repository files navigation

Express Practice

Setup

  • fork, clone, npm install, node index.js
  • A web page has been created for you
  • Your job is to build the server
  • Ignore the client folder
  • Look at http://localhost:3001

Part 1 - Server

index.js

  • This is the starting point of the server, put all code here
  • Make your app listen to port 3001

Body

  • Add body parser middleware to express

Create express routes to get all things

  • Add .get() routes for /contacts, /vehicles, /comments, /products
  • response.json() the appropriate array

Create express routes to get one thing

  • Add .get() routes for /contacts/:id, /vehicles/:id, /comments/:id, /products/:id
  • add a path variable for id
  • use the params.id to .find() the item from the appropriate array
  • response.json() the item found

Create express routes to create one thing

  • Add .post() routes for /contacts, /vehicles, /comments, /products
  • Add the information from the body to the appropriate array

Once completed, the web page should be able to list out the information, create new information and view one item of the information. We don't need to worry about update or delete.

Part 2 - Routes

  • Create route files
  • Organize the routes for /contacts, /vehicles, /comments, /products using express Router
  • Import and use the Routers in index.js

Part 3 - Controllers

  • Create controller files
  • Import the arrays into the controller
  • Take the code from the routes and put it into the controller
  • create functions for list, show and create
  • Import and use the controller functions in the appropiate Router

Part 4 - Database

  • https://github.com/AustinCodingAcademy/express-mongodb
  • Create a database somewhere for advanced-express-practice
  • Create a new file database.js, implement the code for MongoClient and connect()
  • Implement the mongodb client tool into your controllers for list, show, create
  • Use insertMany() for create and find() for list and show
  • How are your controllers going to get access to const db = client.db("advanced-express-practice");

Part 5 - Mongoose

  • In index.js, import and use mongoose. Connect to a database "advanced-express-practice"
  • Create the mongoose models for Contact, Vehicle, Comment Product
  • CommentModel - body
  • ContactModel - name, occupation, avatar
  • VehicleModel - year, make, model
  • ProductModel - name, description
  • Change the code in the controllers to use the Models instead of hard coded arrays

Points

  • Base - 10pts
  • Data shows in the page for the Lists - 5pts each (20pts)
  • Creating data works - 10pts each (40pts)
  • Can view one item at a time by id - 30pts

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published