Vegetables
CRUD, MVC, REST, INDUCES and JSX: Remember where we are going
Learning Objectives
- Practicing index and show, new and create routes with express
Prerequisites
- JavaScript
- Express
- Node
- JSX
Build a Vegetable App with JSX-REACT-VIEWS
- make a directory for your homework
- change into the directory you made
- make a server.js file in that directory
- make models views and controllers folders in that directory
- init npm project in that directory
- init git repository in that directory
- touch
.gitignoreand add.env and node_modulesto the file, write each on it's own line - git add -A && git commit -m "start here"
- touch .env
- add your
MONGO_URI - go to
https://github.com/newand make a new github repo - copy the git link from your new empty git repo
- git remote add origin
- open code in vs code
Step 1
- setup basic express server
- install appropriate packages
express jsx-view-engine react react-dom - look at code from classwork to help you
- You should not google this you are not far enough in the process to get the right information
- You will be able to Google soon if you choose to
Steps
- Add A Model File For Vegetables to your vegetables app
- Create Index, Show, New and Create routes for Vegetables
- Create Index, Show and New
jsxViews - Add 5 Vegetables using your New Page
- Go to
http://localhost:3000/vegetables/new - Create a new
vegetables - See the fruit at
http://localhost:3000/vegetables - Show page for vegetable works
- You can see vegetables in your MongoDB Atlas DB vegetables database
The User Stories
- When a user goes to the
/vegatablesroute they will see anindexof veggies on the page - When a user clicks on the name of the vegetable, they will be taken to that vegetable's
showpage, and will see the vegatables's name and color and if its READYTOEAT. - When a user goes to
/vegetables/newa user sees a form that allows them to create a brand new vegetable, and then redirects the user back to/vegetables
Hints
/views/fruits/Index.jsx
/views/vegetables/Index.jsx
res.render('vegetables/Index', {...})
res.render('fruits/Index', {...})