Hello and Welcome to my coding course to build an ecommerce website like amazon by MERN stack. In this course you will learn the essential tools and skills to design, develop and deploy a fully-function marketplace website using React and Redux in frontend and Node and MongoDB in backend.
- create functional component by react
- use react hooks to handle form inputs
- manage application state by redux using custom hooks
- create backend web api by node and express js
- design database model by mongodb
- perform CRUP operations on orders, products and users by mongoose ORM
- handle authentication and authorization using JsonWebToken
- create seller and admin roles to manage products, orders and users
- handle shopping cart for customer to place orders-
This course is for non-coders or juniors who want to be a professional web developer to get a job in 22 million job opportunities around the world. Basic knowledge of web developments like html, css and basic javascript is necessary for this course.
- Home Screen
- Create react app
- List data using JSX and map function
- Product Screen
- Url routing in react
- Handle events in react
- Cart Screen
- Save and retrieve data in local storage
- Working javascript array functions
- Update summary based on cart changes
- Sign-in and Register Screen
- Create dynamic form
- Input validation in frontend and backend
- Create web server using node.js
- Connect to Mongodb database
- Add registered user to the database
- Authenticate user based on email and password
- Using Jsonwebtoken to authorize users
- Shipping and Payment Screen
- Create wizard form to get user data in multiple steps
- Save user info in the local storage
- Place Order Screen
- Validate and create order in the database
- Order Screen
- Payment with Paypal
- Show order state based on user and admin activities
- Profile Screen
- Create authenticated routes
- enable user to update their informations
- enable user to logout and clear local storage
- show list of orders to user and link it to details
- Seller Menu
- add products, upload files
- manage orders
- Admin Menu
- manage users
- add seller permission
-
Introduction to this course
- what you will build
- what you will learn
- who are audiences
-
Install Tools
- Code Editor
- Web Browser
- VS Code Extension
-
Website Template
- Create amazona folder
- create template folder
- create index.html
- add default HTML code
- link to style.css
- create header, main and footer
- style elements
-
Publish Project To Github
- Initialize git repository
- Commit changes
- Create github account
- Create repo on github
- connect local repo to github repo
- push changes to github
-
Create React App
- npx create-react-app frontend
- npm start
- Remove unused files
- copy index.html content to App.js
- copy style.css content to index.css
- replace class with className
-
Use React Router Dom
- npm install react-router-dom
- define Route
- Create Home Screen
- Create Product Screen
-
List Products on Home Screen
- create data.js
- put 6 products there
- copy product images to images folder
- map data.products to JSX in HomeScreen
- create Product.js component
- update style to products
-
Create Rating Component
- create components/Rating.js
- link to fontawesome.css in index.html
- create div.rating
- define Rating object with render()
- if !props.value return empty div
- else use fa fa-star, fa-star-half-o and fa-star-o
- last span for props.text || ''
- style div.rating, span and last span
- Edit Product component
- Use Rating component
-
Add Sidebar Menu
- create aside element
- put product categories
- add open and close menu
-
Create Product Details Screen
- Create 3 columns for product
- column 1 for image
- column 2 product information
- column 3 from add to cart button
- Add style
-
Create Node.JS Server
- run npm init in root folder
- npm install express
- create server.js
- add start command as node backend/server.js
- require express
- create route for / return backend is ready.
- move products.js from frontend to backend
- create route for /api/products
- return products
- run npm start
-
Load Products From Backend
- edit HomeScreen.js
- define products, loading and error.
- create useEffect
- define async fetchData and call it
- install axios
- get data from /api/products
- show them in the list
-
Install ESlint For Code Linting
- npm install -D eslint
- install VSCode eslint extension
- Set VSCode setting for eslint
- Install prettier extension
- npm install -D eslint-config-prettier
- Add extends: "prettier"
-
Add Redux to Home Screen
- npm install redux react-redux
- Create store.js
- initState= {products:[]}
- reducer = (state, action) => switch LOAD_PRODUCTS: {products: action.payload}
- export default createStore(reducer, initState)
- Edit HomeScreen.js
- shopName = useSelector(state=>state.products)
- const dispatch = useDispatch()
- useEffect(()=>dispatch({type: LOAD_PRODUCTS, payload: data})
- Add store to index.js
-
Show Loading and Message Box
- Create Loading Component
- Create Message Box Component
- Use them in HomeScreen
-
Add Redux to Product Screen
- create product details constants, actions and reducers
- add reducer to store.js
- use action in ProductScreen.js
- add /api/product/:id to backend api
-
Handle Add To Cart Button
- Handle Add To Cart in ProductScreen.js
- create CartScreen.js
-
Implement Add to Cart Action
- create addToCart constants, actions and reducers
- add reducer to store.js
- use action in CartScreen.js
- render cartItems.length
-
Design Cart Screen
- create 2 columns for cart items and cart action
- cartItems.length === 0 ? cart is empty
- show item image, name, qty and price
- cart action
- Subtotal
- Proceed to Checkout button
-
Implement Remove From Cart Action
- create removeFromCart constants, actions and reducers
- add reducer to store.js
- use action in CartScreen.js
-
Switch From Babel To Native Node
- Update node
- Update package.json
- Add .js to imports
-
Insert Sample Data in MongoDB
- npm install mongoose
- connect to mongodb
- create config.js
- npm install dotenv
- export MONGODB_URL
- create models/userModel.js
- create userSchema and userModel
- create models/productModel.js
- create productSchema and productModel
- create userRoute
- Seed sample data
-
Create Sign-in Backend
- create API for /api/users/signin
- create isAuth middleware
-
Design SignIn Screen
- create SigninScreen
- render email and password fields
- create signin constants, actions and reducers
- Update Header based on user login
-
Register Screen
- create RegisterScreen.js
- add form elements
- after_render handle form submit
- create register request in frontend
- create register api in backend
-
User Profile Screen
- create ProfileScreen.js
- add form elements
- after_render handle form submit
- create profile update request in frontend
- create profile update api in backend
- create isAuth in utils.js and use in update profile
- implement sign out
-
Checkout Wizard
- create CheckoutSteps.js
- create div elements for step 1 to 4
- create redirectUser() in utils.js
- copy profile screen and as shipping screen
- use CheckoutStep
- define getShipping and setShipping
- copy shipping screen and as payment screen
- define getPayment and setPayment
- redirect user to PlaceOrder.js
-
PlaceOrder Screen UI
- create PlaceOrder.js
- style elements
-
PlaceOrder Screen Action
- handle place order button click
- createOrder api
- create orderModel
- create orderRouter
- create post order route
-
Order Screen
- create OrderScreen.js
- style elements
-
PayPal Payment
- get client id from paypal
- set it in .env file
- create route form /api/paypal/clientId
- create getPaypalClientID in api.js
- add paypal checkout script in OrderScreen.js
- show paypal button
- update order after payment
- create payOrder in api.js
- create route for /:id/pay in orderRouter.js
- rerender after pay order
-
Display Orders History
- create customer orders api
- create api for getMyOrders
- show orders in profile screen
- style orders
-
Admin Dashboard UI
- Header.js
- if user is admin show Dashboard
- create DashboardScreen
- create DashboardMenu
- Style dashboard
-
Admin Products UI
- create ProductListScreen.js
- show products with edit and delete button
- show create product button
-
Create Product
- create product model
- implement create product route
- create product function in api.js
- call create product function in ProductListScreen
- redirect to edit product
-
Edit Product UI
- create ProductEditScreen.js
- load product data from backend
- handle form submit
- save product in backend
-
Edit Product Backend
- handle form submit
- create updateProduct
- save product in backend
-
Upload Product Image
- npm install multer
- create routes/uploadRoute.js
- import express and multer
- create disk storage with Date.now().jpg as filename
- set upload as multer({ storage })
- router.post('/', upload.single('image'))
- return req.file.path
- app.use('/api/uploads',uploadRoute) in server.js
- create uploads folder and put empty file.txt there.
- ProductEditScreen.js
- create file input and set id to image-file
- after_render() handle image-file change
- create form data
- call uploadProductImage()
- create uploadProductImage in api.js
- update server.js
-
Build Project
- create build script for frontend
- create build script for backend
- update sever.js to serve frontend build folder and uploads folder
- stop running frontend
- npm run build
- check localhost:5000 for running website and showing images
-
Delete Product
- update ProductListScreen.js
- handle delete button
- rerender after deletion
-
Admin Orders
- create Admin Order menu in header
- create AdminOrder.js
- load orders from backend
- list them in the screen
- show delete and edit button
- redirect to order details on edit action
-
Deliver Order
- if order is payed show deliver button for admin
- handle click on deliver button
- set state to delivered
-
Show Summary Report in Dashboard
- create summary section
- style summary
- create summary backend
- create getSummary in api.js
- load data in dashboard screen
- show 3 boxes for Users, Orders and Sales
-
Show Chart in Dashboard
- import chartist
- add chartist css to index.html
- create linear chart for daily sales
- create pie chart for product categories
-
Publish heroku
- Create git repository
- Create heroku account
- Install Heroku CLI
heroku login
heroku apps:create <yourname>-amazona
- Edit package.json
"heroku-postbuild": "cd frontend && npm install && npm run build"
"engines": { "node": "12.4.0", "npm": "6.9.0" }
- Create Procfile
web: node --experimental-modules backend/server.js
- Create MongoDB Atlas Account
- Open cloud.mongodb.com
- Create new database
- Add new user and save username and password
- Set Network Access to accept all requests
- Copy connection string
- Replace db name, username and password with yours.
heroku config:set MONGODB_URL=mongodb+srv://<username>:<password>@cluster0.nb7oz.mongodb.net/<dbname>?retryWrites=true&w=majority
- Set SKIP_PREFLIGHT_CHECK=true
heroku config:set SKIP_PREFLIGHT_CHECK=true
- Commit and push
- Open
https://<yourname>-amazona.herokuapp.com/api/users/seed
- Open
https://<yourname>-amazona.herokuapp.com
-
Product Search Bar
- create search bar in Header.js
- add style
- handle submit form
- edit parse url to get query string
- update product list api for search keyword
-
Show Categories In Sidebar Menu
- create aside-open-button in Header.js
- add event to open aside
- create Aside.js component
- Add style aside
- after render close it on click on close button
- Use it in index.html
- Update index.js to render aside 9.
- call getCategories
- create getCategories in api.js
-
Deploy on AWS Elastic Beanstalk
- Install elastic beanstalk
- add .elasticbeanstalk/ to .gitignore
eb init --platform node.js --region <your region like eu-west-2>
eb create --sample node-express-env
eb open
- create file
.ebextensions/nodecommand.config
- add option_settings
NodeCommand: "npm run serve"
- add commands
command: "sudo chown -R 496:494 /tmp/.npm"
- update package.json add
serve
script cd frontend && npm install && npm run build && cd .. && node --experimental-modules backend/server.js
- Set env variables
eb setenv MONGODB_URL="mongodb+srv://xx"
eb setenv SKIP_PREFLIGHT_CHECK=true
- optional env vars: GOOGLE_API_KEY, PAYPAL_CLIENT_ID and JWT_SECRET
- Commit changes
git add . && git commit
- Deploy on aws
eb deploy
- Watch logs
eb logs -cw enable
- open
httpsconsole.aws.amazon.com/cloudwatch
- select Logs > Log groups > Node.js Logs
-
Deploy on AWS LightSail
- mkdir -p ~/apps/newamazona-final/repo
- mkdir -p ~/apps/newamazona-final/dest
- cd repo
- git --bare init
- nano hooks/post-receive
#!/bin/bash -l export SKIP_PREFLIGHT_CHECK=true echo 'post-receive: Triggered.' cd ~/apps/newamazona-final/dest/ echo 'post-receive: git check out...' git --git-dir=/home/bitnami/apps/newamazona-final/repo/ --work-tree=/home/bitnami/apps/newamazona-final/dest/ checkout master -f echo 'post-receive: npm install...' npm install npm run build forever restart newamazona-final
- chmod ug+x hooks/post-receive
- create .env file in dest folder
- add MONGODB_URL, SKIP_PREFLIGHT_CHECK and PORT=4200
- npm install forever -g
- forever start --uid="newamazona-final" --sourceDir="/home/bitnami/apps/newamazona-final/dest/" backend/server.js
- sudo /opt/bitnami/bncert-tool
- nano /opt/bitnami/apache2/conf/bitnami/bitnami-ssl.conf
<VirtualHost _default_:443> ServerName amazona.webacademy.pro # ... ProxyRequests Off <Proxy *> Order deny,allow Allow from all </Proxy> ProxyPass / http://localhost:4200/ ProxyPassReverse / http://localhost:4200/ # Error Documents ErrorDocument 503 /503.html # ... </VirtualHost>
- sudo /opt/bitnami/ctlscript.sh restart apache
- In Lightsail UI > Network > DNS > Add A amazona subdomain
- In Local computer
- git remote add academy ssh://bitnami@18.133.37.82/home/bitnami/apps/newamazona-final/repo/
- git add . && git commit -m "m" && git push academy
- open https://amazona.webacademy.pro