├── .gitignore ├── .vscode └── launch.json ├── Chapter 10 - Express Deepdive ├── app.js ├── package-lock.json └── package.json ├── Chapter 10 - airbnb ├── app.js ├── package-lock.json ├── package.json ├── routes │ ├── hostRouter.js │ └── userRouter.js ├── utils │ └── pathUtil.js └── views │ ├── 404.html │ ├── addHome.html │ ├── home.html │ └── homeAdded.html ├── Chapter 11 - airbnb styling ├── app.js ├── package-lock.json ├── package.json ├── public │ ├── home.css │ └── output.css ├── routes │ ├── hostRouter.js │ └── userRouter.js ├── tailwind.config.js ├── utils │ └── pathUtil.js └── views │ ├── 404.html │ ├── addHome.html │ ├── home.html │ ├── homeAdded.html │ └── input.css ├── Chapter 12 - Dynamic UI using EJS ├── app.js ├── package-lock.json ├── package.json ├── public │ ├── home.css │ └── output.css ├── routes │ ├── hostRouter.js │ └── userRouter.js ├── tailwind.config.js ├── utils │ └── pathUtil.js └── views │ ├── 404.ejs │ ├── addHome.ejs │ ├── home.ejs │ ├── homeAdded.ejs │ ├── input.css │ └── partials │ ├── head.ejs │ └── nav.ejs ├── Chapter 13 - MVC ├── app.js ├── controllers │ ├── errors.js │ ├── hostController.js │ └── storeController.js ├── data │ └── homes.json ├── models │ └── home.js ├── nodemon.json ├── package-lock.json ├── package.json ├── public │ ├── home.css │ └── output.css ├── routes │ ├── hostRouter.js │ └── storeRouter.js ├── tailwind.config.js ├── utils │ └── pathUtil.js └── views │ ├── 404.ejs │ ├── host │ ├── addHome.ejs │ ├── edit-home.ejs │ ├── home-added.ejs │ └── host-home-list.ejs │ ├── input.css │ ├── partials │ ├── head.ejs │ └── nav.ejs │ └── store │ ├── bookings.ejs │ ├── favourite-list.ejs │ ├── home-detail.ejs │ ├── home-list.ejs │ ├── index.ejs │ └── reserve.ejs ├── Chapter 14 - Dynamic Paths ├── app.js ├── controllers │ ├── errors.js │ ├── hostController.js │ └── storeController.js ├── data │ ├── favourite.json │ └── homes.json ├── models │ ├── favourite.js │ └── home.js ├── nodemon.json ├── package-lock.json ├── package.json ├── public │ ├── home.css │ ├── images │ │ ├── house1.png │ │ ├── house2.png │ │ ├── house3.png │ │ ├── house4.png │ │ ├── house5.png │ │ ├── house6.png │ │ ├── house7.png │ │ └── house8.png │ └── output.css ├── routes │ ├── hostRouter.js │ └── storeRouter.js ├── tailwind.config.js ├── utils │ └── pathUtil.js └── views │ ├── 404.ejs │ ├── host │ ├── edit-home.ejs │ └── host-home-list.ejs │ ├── input.css │ ├── partials │ ├── favourite.ejs │ ├── head.ejs │ └── nav.ejs │ └── store │ ├── bookings.ejs │ ├── favourite-list.ejs │ ├── home-detail.ejs │ ├── home-list.ejs │ ├── index.ejs │ └── reserve.ejs ├── Chapter 15 - Introduction to SQL ├── app.js ├── controllers │ ├── errors.js │ ├── hostController.js │ └── storeController.js ├── data │ └── favourite.json ├── models │ ├── favourite.js │ └── home.js ├── nodemon.json ├── package-lock.json ├── package.json ├── public │ ├── home.css │ ├── images │ │ ├── house1.png │ │ ├── house2.png │ │ ├── house3.png │ │ ├── house4.png │ │ ├── house5.png │ │ ├── house6.png │ │ ├── house7.png │ │ └── house8.png │ └── output.css ├── routes │ ├── hostRouter.js │ └── storeRouter.js ├── tailwind.config.js ├── utils │ ├── databaseUtil.js │ └── pathUtil.js └── views │ ├── 404.ejs │ ├── host │ ├── edit-home.ejs │ └── host-home-list.ejs │ ├── input.css │ ├── partials │ ├── favourite.ejs │ ├── head.ejs │ └── nav.ejs │ └── store │ ├── bookings.ejs │ ├── favourite-list.ejs │ ├── home-detail.ejs │ ├── home-list.ejs │ ├── index.ejs │ └── reserve.ejs ├── Chapter 16 - Introduction to MongoDB ├── app.js ├── controllers │ ├── errors.js │ ├── hostController.js │ └── storeController.js ├── models │ ├── favourite.js │ └── home.js ├── nodemon.json ├── package-lock.json ├── package.json ├── public │ ├── home.css │ ├── images │ │ ├── house1.png │ │ ├── house2.png │ │ ├── house3.png │ │ ├── house4.png │ │ ├── house5.png │ │ ├── house6.png │ │ ├── house7.png │ │ └── house8.png │ └── output.css ├── routes │ ├── hostRouter.js │ └── storeRouter.js ├── tailwind.config.js ├── utils │ ├── databaseUtil.js │ └── pathUtil.js └── views │ ├── 404.ejs │ ├── host │ ├── edit-home.ejs │ └── host-home-list.ejs │ ├── input.css │ ├── partials │ ├── favourite.ejs │ ├── head.ejs │ └── nav.ejs │ └── store │ ├── bookings.ejs │ ├── favourite-list.ejs │ ├── home-detail.ejs │ ├── home-list.ejs │ ├── index.ejs │ └── reserve.ejs ├── Chapter 17 - Introduction to Mongoose ├── app.js ├── controllers │ ├── errors.js │ ├── hostController.js │ └── storeController.js ├── models │ ├── favourite.js │ └── home.js ├── nodemon.json ├── package-lock.json ├── package.json ├── public │ ├── home.css │ ├── images │ │ ├── house1.png │ │ ├── house2.png │ │ ├── house3.png │ │ ├── house4.png │ │ ├── house5.png │ │ ├── house6.png │ │ ├── house7.png │ │ └── house8.png │ └── output.css ├── routes │ ├── hostRouter.js │ └── storeRouter.js ├── tailwind.config.js ├── utils │ └── pathUtil.js └── views │ ├── 404.ejs │ ├── host │ ├── edit-home.ejs │ └── host-home-list.ejs │ ├── input.css │ ├── partials │ ├── favourite.ejs │ ├── head.ejs │ └── nav.ejs │ └── store │ ├── bookings.ejs │ ├── favourite-list.ejs │ ├── home-detail.ejs │ ├── home-list.ejs │ ├── index.ejs │ └── reserve.ejs ├── Chapter 18 - Cookies and Sessions ├── app.js ├── controllers │ ├── authController.js │ ├── errors.js │ ├── hostController.js │ └── storeController.js ├── models │ ├── favourite.js │ └── home.js ├── nodemon.json ├── package-lock.json ├── package.json ├── public │ ├── home.css │ ├── images │ │ ├── house1.png │ │ ├── house2.png │ │ ├── house3.png │ │ ├── house4.png │ │ ├── house5.png │ │ ├── house6.png │ │ ├── house7.png │ │ └── house8.png │ └── output.css ├── routes │ ├── authRouter.js │ ├── hostRouter.js │ └── storeRouter.js ├── tailwind.config.js ├── utils │ └── pathUtil.js └── views │ ├── 404.ejs │ ├── auth │ └── login.ejs │ ├── host │ ├── edit-home.ejs │ └── host-home-list.ejs │ ├── input.css │ ├── partials │ ├── favourite.ejs │ ├── head.ejs │ └── nav.ejs │ └── store │ ├── bookings.ejs │ ├── favourite-list.ejs │ ├── home-detail.ejs │ ├── home-list.ejs │ ├── index.ejs │ └── reserve.ejs ├── Chapter 19 - Authentication and Authorization ├── app.js ├── controllers │ ├── authController.js │ ├── errors.js │ ├── hostController.js │ └── storeController.js ├── models │ ├── home.js │ └── user.js ├── nodemon.json ├── package-lock.json ├── package.json ├── public │ ├── home.css │ ├── images │ │ ├── house1.png │ │ ├── house2.png │ │ ├── house3.png │ │ ├── house4.png │ │ ├── house5.png │ │ ├── house6.png │ │ ├── house7.png │ │ └── house8.png │ └── output.css ├── routes │ ├── authRouter.js │ ├── hostRouter.js │ └── storeRouter.js ├── tailwind.config.js ├── utils │ └── pathUtil.js └── views │ ├── 404.ejs │ ├── auth │ ├── login.ejs │ └── signup.ejs │ ├── host │ ├── edit-home.ejs │ └── host-home-list.ejs │ ├── input.css │ ├── partials │ ├── errors.ejs │ ├── favourite.ejs │ ├── head.ejs │ └── nav.ejs │ └── store │ ├── bookings.ejs │ ├── favourite-list.ejs │ ├── home-detail.ejs │ ├── home-list.ejs │ ├── index.ejs │ └── reserve.ejs ├── Chapter 2 - First NodeJS Program ├── first.js └── output.txt ├── Chapter 20 - Image Upload and Download ├── app.js ├── controllers │ ├── authController.js │ ├── errors.js │ ├── hostController.js │ └── storeController.js ├── models │ ├── home.js │ └── user.js ├── nodemon.json ├── package-lock.json ├── package.json ├── public │ ├── home.css │ ├── images │ │ ├── house1.png │ │ ├── house2.png │ │ ├── house3.png │ │ ├── house4.png │ │ ├── house5.png │ │ ├── house6.png │ │ ├── house7.png │ │ └── house8.png │ └── output.css ├── routes │ ├── authRouter.js │ ├── hostRouter.js │ └── storeRouter.js ├── tailwind.config.js ├── uploads │ └── dempoltkuv-146.png ├── utils │ └── pathUtil.js └── views │ ├── 404.ejs │ ├── auth │ ├── login.ejs │ └── signup.ejs │ ├── host │ ├── edit-home.ejs │ └── host-home-list.ejs │ ├── input.css │ ├── partials │ ├── errors.ejs │ ├── favourite.ejs │ ├── head.ejs │ └── nav.ejs │ └── store │ ├── bookings.ejs │ ├── favourite-list.ejs │ ├── home-detail.ejs │ ├── home-list.ejs │ ├── index.ejs │ └── reserve.ejs ├── Chapter 21 - REST API and Json Requests ├── todo-backend │ ├── app.js │ ├── controllers │ │ ├── errors.js │ │ └── todoItemsController.js │ ├── models │ │ └── TodoItem.js │ ├── nodemon.json │ ├── package-lock.json │ ├── package.json │ ├── public │ │ ├── home.css │ │ └── output.css │ ├── routes │ │ └── todoItemsRouter.js │ ├── tailwind.config.js │ └── utils │ │ └── pathUtil.js └── todo-frontend │ ├── .eslintrc.cjs │ ├── .gitignore │ ├── README.md │ ├── index.html │ ├── package-lock.json │ ├── package.json │ ├── public │ └── vite.svg │ ├── src │ ├── App.css │ ├── App.jsx │ ├── assets │ │ └── react.svg │ ├── components │ │ ├── AddTodo.jsx │ │ ├── AppName.jsx │ │ ├── TodoItem.jsx │ │ ├── TodoItems.jsx │ │ └── WelcomeMessage.jsx │ ├── main.jsx │ └── services │ │ └── itemsService.js │ └── vite.config.js ├── Chapter 3 - First Node Server └── app.js ├── Chapter 4 - Request and Reponse ├── app.js ├── practise.js ├── user.js └── user.txt ├── Chapter 5 - Parsing Request ├── app.js ├── calculator │ ├── app.js │ ├── handler.js │ └── sum.js ├── user.js └── user.txt ├── Chapter 6 - Event Loop ├── calculator │ ├── app.js │ ├── handler.js │ └── sum.js └── user │ ├── app.js │ ├── user.js │ └── user.txt ├── Chapter 7 - npm and Tools ├── app.js ├── package-lock.json └── package.json ├── Chapter 8 - Errors and Debugging ├── app.js ├── logical.js ├── package-lock.json ├── package.json ├── runtime.js ├── syntax.js └── user.js ├── Chapter 9 - Introduction to Express ├── app.js ├── package-lock.json └── package.json ├── Complete NodeJS Notes.pdf ├── Practise Set ├── Chapter 10 - Contact Us │ ├── app.js │ ├── package-lock.json │ ├── package.json │ ├── routes │ │ ├── contactRouter.js │ │ └── homeRouter.js │ ├── utils │ │ └── pathUtil.js │ └── views │ │ ├── 404.html │ │ ├── contact-success.html │ │ ├── contact-us.html │ │ └── home.html ├── Chapter 12 - Dynamic │ ├── app.js │ ├── package-lock.json │ ├── package.json │ ├── public │ │ ├── home.css │ │ └── output.css │ ├── routes │ │ ├── hostRouter.js │ │ └── userRouter.js │ ├── tailwind.config.js │ ├── utils │ │ └── pathUtil.js │ └── views │ │ ├── 404.ejs │ │ ├── addHome.ejs │ │ ├── home.ejs │ │ ├── homeAdded.ejs │ │ ├── input.css │ │ └── partials │ │ ├── head.ejs │ │ └── nav.ejs └── Chapter 9 - Contact Us │ ├── app.js │ ├── package-lock.json │ └── package.json └── README.md /.vscode/launch.json: -------------------------------------------------------------------------------- 1 | { 2 | // Use IntelliSense to learn about possible attributes. 3 | // Hover to view descriptions of existing attributes. 4 | // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 5 | "version": "0.2.0", 6 | "configurations": [ 7 | { 8 | "type": "node", 9 | "request": "launch", 10 | "name": "Launch Program", 11 | "skipFiles": [ 12 | "/**" 13 | ], 14 | "program": "${workspaceFolder}/Chapter 8 - Errors and Debugging/user.js", 15 | "restart": true, 16 | "runtimeExecutable": "nodemon", 17 | "console": "integratedTerminal" 18 | } 19 | ] 20 | } -------------------------------------------------------------------------------- /Chapter 10 - Express Deepdive/app.js: -------------------------------------------------------------------------------- 1 | // External Module 2 | const express = require('express'); 3 | const bodyParser = require('body-parser'); 4 | 5 | const app = express(); 6 | 7 | app.use((req, res, next) => { 8 | console.log("First Dummy Middleware", req.url, req.method); 9 | next(); 10 | }); 11 | 12 | app.use((req, res, next) => { 13 | console.log("Second Dummy Middleware", req.url, req.method); 14 | next(); 15 | }); 16 | 17 | // app.use((req, res, next) => { 18 | // console.log("Third Middleware", req.url, req.method); 19 | // res.send("

Welcome to Complete Coding

"); 20 | // }); 21 | 22 | app.get("/", (req, res, next) => { 23 | console.log("Handling / for GET", req.url, req.method); 24 | res.send(`

Welcome to Complete Coding

`); 25 | }) 26 | 27 | app.get("/contact-us", (req, res, next) => { 28 | console.log("Handling /contact-us for GET", req.url, req.method); 29 | res.send( 30 | `

Please give your details here

31 |
32 | 33 | 34 | 35 |
36 | `); 37 | }); 38 | 39 | app.post("/contact-us", (req, res, next) => { 40 | console.log("First handling", req.url, req.method, req.body); 41 | next(); 42 | }) 43 | 44 | app.use(bodyParser.urlencoded()); 45 | 46 | app.post("/contact-us", (req, res, next) => { 47 | console.log("Handling /contact-us for POST", req.url, req.method, req.body); 48 | res.send(`

We will contact you shortly

`); 49 | }) 50 | 51 | const PORT = 3000; 52 | app.listen(PORT, () => { 53 | console.log(`Server running on address http://localhost:${PORT}`); 54 | }); -------------------------------------------------------------------------------- /Chapter 10 - Express Deepdive/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "chapter-9---contact-us", 3 | "version": "1.0.0", 4 | "main": "index.js", 5 | "scripts": { 6 | "test": "echo \"Error: no test specified\" && exit 1", 7 | "start": "nodemon app.js" 8 | }, 9 | "keywords": [], 10 | "author": "", 11 | "license": "ISC", 12 | "description": "", 13 | "devDependencies": { 14 | "nodemon": "^3.1.7" 15 | }, 16 | "dependencies": { 17 | "body-parser": "^1.20.3", 18 | "express": "^4.21.0" 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /Chapter 10 - airbnb/app.js: -------------------------------------------------------------------------------- 1 | // Core Module 2 | const path = require('path'); 3 | 4 | // External Module 5 | const express = require('express'); 6 | 7 | //Local Module 8 | const userRouter = require("./routes/userRouter") 9 | const hostRouter = require("./routes/hostRouter") 10 | const rootDir = require("./utils/pathUtil"); 11 | 12 | const app = express(); 13 | 14 | app.use(express.urlencoded()); 15 | app.use(userRouter); 16 | app.use("/host", hostRouter); 17 | 18 | app.use((req, res, next) => { 19 | res.status(404).sendFile(path.join(rootDir, 'views', '404.html')); 20 | }) 21 | 22 | const PORT = 3000; 23 | app.listen(PORT, () => { 24 | console.log(`Server running on address http://localhost:${PORT}`); 25 | }); -------------------------------------------------------------------------------- /Chapter 10 - airbnb/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "chapter-10---airbnb", 3 | "version": "1.0.0", 4 | "main": "index.js", 5 | "scripts": { 6 | "test": "echo \"Error: no test specified\" && exit 1", 7 | "start": "nodemon app.js" 8 | }, 9 | "keywords": [], 10 | "author": "", 11 | "license": "ISC", 12 | "description": "", 13 | "devDependencies": { 14 | "nodemon": "^3.1.7" 15 | }, 16 | "dependencies": { 17 | "body-parser": "^1.20.3", 18 | "express": "^4.21.0" 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /Chapter 10 - airbnb/routes/hostRouter.js: -------------------------------------------------------------------------------- 1 | // Core Module 2 | const path = require('path'); 3 | 4 | // External Module 5 | const express = require('express'); 6 | const hostRouter = express.Router(); 7 | 8 | // Local Module 9 | const rootDir = require("../utils/pathUtil"); 10 | 11 | hostRouter.get("/add-home", (req, res, next) => { 12 | res.sendFile(path.join(rootDir, 'views', 'addHome.html')); 13 | }) 14 | 15 | hostRouter.post("/add-home", (req, res, next) => { 16 | res.sendFile(path.join(rootDir, 'views', 'homeAdded.html')); 17 | }) 18 | 19 | module.exports = hostRouter; -------------------------------------------------------------------------------- /Chapter 10 - airbnb/routes/userRouter.js: -------------------------------------------------------------------------------- 1 | // Core Modules 2 | const path = require('path'); 3 | 4 | // External Module 5 | const express = require('express'); 6 | const userRouter = express.Router(); 7 | 8 | // Local Module 9 | const rootDir = require("../utils/pathUtil"); 10 | 11 | userRouter.get("/", (req, res, next) => { 12 | res.sendFile(path.join(rootDir, 'views', 'home.html')); 13 | }); 14 | 15 | module.exports = userRouter; -------------------------------------------------------------------------------- /Chapter 10 - airbnb/utils/pathUtil.js: -------------------------------------------------------------------------------- 1 | // Core Module 2 | const path = require('path'); 3 | 4 | module.exports = path.dirname(require.main.filename); -------------------------------------------------------------------------------- /Chapter 10 - airbnb/views/404.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | Page Not Found 7 | 8 | 9 |
10 |

404 Your page is not found on airbnb

11 |
12 | 13 | -------------------------------------------------------------------------------- /Chapter 10 - airbnb/views/addHome.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | Add Home to airbnb 7 | 8 | 9 |
10 |

Register your home here:

11 |
12 |
13 |
14 | 19 | 20 |
21 |
22 | 23 | 24 | -------------------------------------------------------------------------------- /Chapter 10 - airbnb/views/home.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | airbnb Home 7 | 8 | 9 |
10 |

Welcome to airbnb

11 |
12 |
13 | Add Home 14 |
15 | 16 | 17 | -------------------------------------------------------------------------------- /Chapter 10 - airbnb/views/homeAdded.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | Home Added Successfully 7 | 8 | 9 |
10 |

Home Registered successfully

11 |
12 |
13 | Go to Home 14 |
15 | 16 | 17 | -------------------------------------------------------------------------------- /Chapter 11 - airbnb styling/app.js: -------------------------------------------------------------------------------- 1 | // Core Module 2 | const path = require('path'); 3 | 4 | // External Module 5 | const express = require('express'); 6 | 7 | //Local Module 8 | const userRouter = require("./routes/userRouter") 9 | const hostRouter = require("./routes/hostRouter") 10 | const rootDir = require("./utils/pathUtil"); 11 | 12 | const app = express(); 13 | 14 | app.use(express.urlencoded()); 15 | app.use(userRouter); 16 | app.use("/host", hostRouter); 17 | 18 | app.use(express.static(path.join(rootDir, 'public'))) 19 | 20 | app.use((req, res, next) => { 21 | res.status(404).sendFile(path.join(rootDir, 'views', '404.html')); 22 | }) 23 | 24 | const PORT = 3000; 25 | app.listen(PORT, () => { 26 | console.log(`Server running on address http://localhost:${PORT}`); 27 | }); -------------------------------------------------------------------------------- /Chapter 11 - airbnb styling/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "chapter-10---airbnb", 3 | "version": "1.0.0", 4 | "main": "index.js", 5 | "scripts": { 6 | "test": "echo \"Error: no test specified\" && exit 1", 7 | "start": "nodemon app.js" 8 | }, 9 | "keywords": [], 10 | "author": "", 11 | "license": "ISC", 12 | "description": "", 13 | "devDependencies": { 14 | "autoprefixer": "^10.4.20", 15 | "nodemon": "^3.1.7", 16 | "postcss": "^8.4.47", 17 | "tailwindcss": "^3.4.13" 18 | }, 19 | "dependencies": { 20 | "body-parser": "^1.20.3", 21 | "express": "^4.21.0" 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /Chapter 11 - airbnb styling/public/home.css: -------------------------------------------------------------------------------- 1 | body { 2 | font-family: 'Arial', sans-serif; 3 | margin: 0; 4 | padding: 0; 5 | background-color: #f5f5f5; 6 | } 7 | 8 | header { 9 | background-color: #ff5a5f; 10 | padding: 1rem 2rem; 11 | box-shadow: 0px 2px 8px rgba(0, 0, 0, 0.1); 12 | } 13 | 14 | nav { 15 | display: flex; 16 | justify-content: space-between; 17 | align-items: center; 18 | } 19 | 20 | nav ul { 21 | list-style: none; 22 | margin: 0; 23 | padding: 0; 24 | display: flex; 25 | } 26 | 27 | nav li { 28 | margin-left: 20px; 29 | } 30 | 31 | nav a { 32 | text-decoration: none; 33 | color: white; 34 | font-weight: bold; 35 | padding: 0.5rem 1rem; 36 | border-radius: 4px; 37 | transition: background-color 0.3s ease; 38 | } 39 | 40 | nav a:hover { 41 | background-color: #e54e52; 42 | } 43 | 44 | main { 45 | text-align: center; 46 | padding: 5rem 2rem; 47 | background-color: #fff; 48 | box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1); 49 | margin: 2rem auto; 50 | max-width: 600px; 51 | border-radius: 8px; 52 | } 53 | 54 | h2 { 55 | color: #333; 56 | font-size: 2rem; 57 | } -------------------------------------------------------------------------------- /Chapter 11 - airbnb styling/routes/hostRouter.js: -------------------------------------------------------------------------------- 1 | // Core Module 2 | const path = require('path'); 3 | 4 | // External Module 5 | const express = require('express'); 6 | const hostRouter = express.Router(); 7 | 8 | // Local Module 9 | const rootDir = require("../utils/pathUtil"); 10 | 11 | hostRouter.get("/add-home", (req, res, next) => { 12 | res.sendFile(path.join(rootDir, 'views', 'addHome.html')); 13 | }) 14 | 15 | hostRouter.post("/add-home", (req, res, next) => { 16 | res.sendFile(path.join(rootDir, 'views', 'homeAdded.html')); 17 | }) 18 | 19 | module.exports = hostRouter; -------------------------------------------------------------------------------- /Chapter 11 - airbnb styling/routes/userRouter.js: -------------------------------------------------------------------------------- 1 | // Core Modules 2 | const path = require('path'); 3 | 4 | // External Module 5 | const express = require('express'); 6 | const userRouter = express.Router(); 7 | 8 | // Local Module 9 | const rootDir = require("../utils/pathUtil"); 10 | 11 | userRouter.get("/", (req, res, next) => { 12 | res.sendFile(path.join(rootDir, 'views', 'home.html')); 13 | }); 14 | 15 | module.exports = userRouter; -------------------------------------------------------------------------------- /Chapter 11 - airbnb styling/tailwind.config.js: -------------------------------------------------------------------------------- 1 | /** @type {import('tailwindcss').Config} */ 2 | module.exports = { 3 | content: ["./views/*.html"], 4 | theme: { 5 | extend: {}, 6 | }, 7 | plugins: [], 8 | } 9 | 10 | -------------------------------------------------------------------------------- /Chapter 11 - airbnb styling/utils/pathUtil.js: -------------------------------------------------------------------------------- 1 | // Core Module 2 | const path = require('path'); 3 | 4 | module.exports = path.dirname(require.main.filename); -------------------------------------------------------------------------------- /Chapter 11 - airbnb styling/views/404.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | Page Not Found 7 | 8 | 9 |
10 |

404 Your page is not found on airbnb

11 |
12 | 13 | -------------------------------------------------------------------------------- /Chapter 11 - airbnb styling/views/addHome.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | Add Home to airbnb 7 | 8 | 9 |
10 |

Register your home here:

11 |
12 |
13 |
14 | 19 | 20 |
21 |
22 | 23 | 24 | -------------------------------------------------------------------------------- /Chapter 11 - airbnb styling/views/home.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | airbnb Home 7 | 8 | 9 | 10 |
11 |

Welcome to airbnb

12 |
13 |
14 | Add Home 15 |
16 | 17 | 18 | -------------------------------------------------------------------------------- /Chapter 11 - airbnb styling/views/homeAdded.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | Home Added Successfully 7 | 8 | 9 |
10 |

Home Registered successfully

11 |
12 |
13 | Go to Home 14 |
15 | 16 | 17 | -------------------------------------------------------------------------------- /Chapter 11 - airbnb styling/views/input.css: -------------------------------------------------------------------------------- 1 | @tailwind base; 2 | @tailwind components; 3 | @tailwind utilities; -------------------------------------------------------------------------------- /Chapter 12 - Dynamic UI using EJS/app.js: -------------------------------------------------------------------------------- 1 | // Core Module 2 | const path = require('path'); 3 | 4 | // External Module 5 | const express = require('express'); 6 | 7 | //Local Module 8 | const userRouter = require("./routes/userRouter") 9 | const {hostRouter} = require("./routes/hostRouter") 10 | const rootDir = require("./utils/pathUtil"); 11 | 12 | const app = express(); 13 | 14 | app.set('view engine', 'ejs'); 15 | app.set('views', 'views'); 16 | 17 | app.use(express.urlencoded()); 18 | app.use(userRouter); 19 | app.use("/host", hostRouter); 20 | 21 | app.use(express.static(path.join(rootDir, 'public'))) 22 | 23 | app.use((req, res, next) => { 24 | res.status(404).render('404', {pageTitle: 'Page Not Found'}); 25 | }) 26 | 27 | const PORT = 3000; 28 | app.listen(PORT, () => { 29 | console.log(`Server running on address http://localhost:${PORT}`); 30 | }); -------------------------------------------------------------------------------- /Chapter 12 - Dynamic UI using EJS/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "chapter-10---airbnb", 3 | "version": "1.0.0", 4 | "main": "index.js", 5 | "scripts": { 6 | "test": "echo \"Error: no test specified\" && exit 1", 7 | "tailwind": "tailwindcss -i ./views/input.css -o ./public/output.css --watch", 8 | "start": "nodemon app.js & npm run tailwind" 9 | }, 10 | "keywords": [], 11 | "author": "", 12 | "license": "ISC", 13 | "description": "", 14 | "devDependencies": { 15 | "autoprefixer": "^10.4.20", 16 | "nodemon": "^3.1.7", 17 | "postcss": "^8.4.47", 18 | "tailwindcss": "^3.4.13" 19 | }, 20 | "dependencies": { 21 | "body-parser": "^1.20.3", 22 | "ejs": "^3.1.10", 23 | "express": "^4.21.0" 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /Chapter 12 - Dynamic UI using EJS/public/home.css: -------------------------------------------------------------------------------- 1 | body { 2 | font-family: 'Arial', sans-serif; 3 | margin: 0; 4 | padding: 0; 5 | background-color: #f5f5f5; 6 | } 7 | 8 | header { 9 | background-color: #ff5a5f; 10 | padding: 1rem 2rem; 11 | box-shadow: 0px 2px 8px rgba(0, 0, 0, 0.1); 12 | } 13 | 14 | nav { 15 | display: flex; 16 | justify-content: space-between; 17 | align-items: center; 18 | } 19 | 20 | nav ul { 21 | list-style: none; 22 | margin: 0; 23 | padding: 0; 24 | display: flex; 25 | } 26 | 27 | nav li { 28 | margin-left: 20px; 29 | } 30 | 31 | nav a { 32 | text-decoration: none; 33 | color: white; 34 | font-weight: bold; 35 | padding: 0.5rem 1rem; 36 | border-radius: 4px; 37 | transition: background-color 0.3s ease; 38 | } 39 | 40 | nav a:hover { 41 | background-color: #e54e52; 42 | } 43 | 44 | main { 45 | text-align: center; 46 | padding: 5rem 2rem; 47 | background-color: #fff; 48 | box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1); 49 | margin: 2rem auto; 50 | max-width: 600px; 51 | border-radius: 8px; 52 | } 53 | 54 | h2 { 55 | color: #333; 56 | font-size: 2rem; 57 | } -------------------------------------------------------------------------------- /Chapter 12 - Dynamic UI using EJS/routes/hostRouter.js: -------------------------------------------------------------------------------- 1 | // Core Module 2 | const path = require('path'); 3 | 4 | // External Module 5 | const express = require('express'); 6 | const hostRouter = express.Router(); 7 | 8 | // Local Module 9 | const rootDir = require("../utils/pathUtil"); 10 | 11 | hostRouter.get("/add-home", (req, res, next) => { 12 | res.render('addHome', {pageTitle: 'Add Home to airbnb'}); 13 | }) 14 | 15 | const registeredHomes = []; 16 | 17 | hostRouter.post("/add-home", (req, res, next) => { 18 | console.log('Home Registration successful for:', req.body, req.body.houseName); 19 | registeredHomes.push({houseName: req.body.houseName}); 20 | res.render('homeAdded', {pageTitle: 'Home Added Successfully'}); 21 | }) 22 | 23 | exports.hostRouter = hostRouter; 24 | exports.registeredHomes = registeredHomes; 25 | -------------------------------------------------------------------------------- /Chapter 12 - Dynamic UI using EJS/routes/userRouter.js: -------------------------------------------------------------------------------- 1 | // Core Modules 2 | const path = require('path'); 3 | 4 | // External Module 5 | const express = require('express'); 6 | const userRouter = express.Router(); 7 | 8 | // Local Module 9 | const { registeredHomes } = require('./hostRouter'); 10 | 11 | userRouter.get("/", (req, res, next) => { 12 | console.log(registeredHomes); 13 | res.render('home', {registeredHomes: registeredHomes, pageTitle: 'airbnb Home'}); 14 | }); 15 | 16 | module.exports = userRouter; -------------------------------------------------------------------------------- /Chapter 12 - Dynamic UI using EJS/tailwind.config.js: -------------------------------------------------------------------------------- 1 | /** @type {import('tailwindcss').Config} */ 2 | module.exports = { 3 | content: ["./views/*.html"], 4 | theme: { 5 | extend: {}, 6 | }, 7 | plugins: [], 8 | } 9 | 10 | -------------------------------------------------------------------------------- /Chapter 12 - Dynamic UI using EJS/utils/pathUtil.js: -------------------------------------------------------------------------------- 1 | // Core Module 2 | const path = require('path'); 3 | 4 | module.exports = path.dirname(require.main.filename); -------------------------------------------------------------------------------- /Chapter 12 - Dynamic UI using EJS/views/404.ejs: -------------------------------------------------------------------------------- 1 | <%- include('partials/head') %> 2 | 3 | 4 | <%- include('partials/nav') %> 5 |
6 |

404

7 |

Oops! Page Not Found

8 | Go Back Home 13 |
14 | 15 | 16 | -------------------------------------------------------------------------------- /Chapter 12 - Dynamic UI using EJS/views/addHome.ejs: -------------------------------------------------------------------------------- 1 | <%- include('partials/head') %> 2 | 3 | 4 | <%- include('partials/nav') %> 5 |
6 |

Register Your Home on AirBnB

7 |
8 | 14 | 15 |
16 |
17 | 18 | 19 | -------------------------------------------------------------------------------- /Chapter 12 - Dynamic UI using EJS/views/home.ejs: -------------------------------------------------------------------------------- 1 | <%- include('partials/head') %> 2 | 3 | 4 | <%- include('partials/nav') %> 5 |
6 |

7 | Here are our registered homes: 8 |

9 | 16 |
17 | 18 | 19 | -------------------------------------------------------------------------------- /Chapter 12 - Dynamic UI using EJS/views/homeAdded.ejs: -------------------------------------------------------------------------------- 1 | <%- include('partials/head') %> 2 | 3 | 4 | <%- include('partials/nav') %> 5 |
6 |
7 |

Home Registered Successfully

8 |

Your home has been added to our listings.

9 | Return to Home 10 |
11 |
12 | 13 | 14 | -------------------------------------------------------------------------------- /Chapter 12 - Dynamic UI using EJS/views/input.css: -------------------------------------------------------------------------------- 1 | @tailwind base; 2 | @tailwind components; 3 | @tailwind utilities; -------------------------------------------------------------------------------- /Chapter 12 - Dynamic UI using EJS/views/partials/head.ejs: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | <%= pageTitle %> 7 | -------------------------------------------------------------------------------- /Chapter 12 - Dynamic UI using EJS/views/partials/nav.ejs: -------------------------------------------------------------------------------- 1 |
2 | 20 |
-------------------------------------------------------------------------------- /Chapter 13 - MVC/app.js: -------------------------------------------------------------------------------- 1 | // Core Module 2 | const path = require('path'); 3 | 4 | // External Module 5 | const express = require('express'); 6 | 7 | //Local Module 8 | const storeRouter = require("./routes/storeRouter") 9 | const hostRouter = require("./routes/hostRouter") 10 | const rootDir = require("./utils/pathUtil"); 11 | const errorsController = require("./controllers/errors"); 12 | 13 | const app = express(); 14 | 15 | app.set('view engine', 'ejs'); 16 | app.set('views', 'views'); 17 | 18 | app.use(express.urlencoded()); 19 | app.use(storeRouter); 20 | app.use("/host", hostRouter); 21 | 22 | app.use(express.static(path.join(rootDir, 'public'))) 23 | 24 | app.use(errorsController.pageNotFound); 25 | 26 | const PORT = 3000; 27 | app.listen(PORT, () => { 28 | console.log(`Server running on address http://localhost:${PORT}`); 29 | }); -------------------------------------------------------------------------------- /Chapter 13 - MVC/controllers/errors.js: -------------------------------------------------------------------------------- 1 | exports.pageNotFound = (req, res, next) => { 2 | res 3 | .status(404) 4 | .render("404", { pageTitle: "Page Not Found", currentPage: "404" }); 5 | }; 6 | -------------------------------------------------------------------------------- /Chapter 13 - MVC/controllers/hostController.js: -------------------------------------------------------------------------------- 1 | const Home = require("../models/home"); 2 | 3 | exports.getAddHome = (req, res, next) => { 4 | res.render("host/addHome", { 5 | pageTitle: "Add Home to airbnb", 6 | currentPage: "addHome", 7 | }); 8 | }; 9 | 10 | exports.getHostHomes = (req, res, next) => { 11 | Home.fetchAll((registeredHomes) => 12 | res.render("host/host-home-list", { 13 | registeredHomes: registeredHomes, 14 | pageTitle: "Host Homes List", 15 | currentPage: "host-homes", 16 | }) 17 | ); 18 | }; 19 | 20 | exports.postAddHome = (req, res, next) => { 21 | const { houseName, price, location, rating, photoUrl } = req.body; 22 | const home = new Home(houseName, price, location, rating, photoUrl); 23 | home.save(); 24 | 25 | res.render("host/home-added", { 26 | pageTitle: "Home Added Successfully", 27 | currentPage: "homeAdded", 28 | }); 29 | }; 30 | -------------------------------------------------------------------------------- /Chapter 13 - MVC/controllers/storeController.js: -------------------------------------------------------------------------------- 1 | const Home = require("../models/home"); 2 | 3 | exports.getIndex = (req, res, next) => { 4 | Home.fetchAll((registeredHomes) => 5 | res.render("store/index", { 6 | registeredHomes: registeredHomes, 7 | pageTitle: "airbnb Home", 8 | currentPage: "index", 9 | }) 10 | ); 11 | }; 12 | 13 | exports.getHomes = (req, res, next) => { 14 | Home.fetchAll((registeredHomes) => 15 | res.render("store/home-list", { 16 | registeredHomes: registeredHomes, 17 | pageTitle: "Homes List", 18 | currentPage: "Home", 19 | }) 20 | ); 21 | }; 22 | 23 | exports.getBookings = (req, res, next) => { 24 | res.render("store/bookings", { 25 | pageTitle: "My Bookings", 26 | currentPage: "bookings", 27 | }) 28 | }; 29 | 30 | exports.getFavouriteList = (req, res, next) => { 31 | Home.fetchAll((registeredHomes) => 32 | res.render("store/favourite-list", { 33 | registeredHomes: registeredHomes, 34 | pageTitle: "My Favourites", 35 | currentPage: "favourites", 36 | }) 37 | ); 38 | }; 39 | -------------------------------------------------------------------------------- /Chapter 13 - MVC/data/homes.json: -------------------------------------------------------------------------------- 1 | [{"houseName":"Utsav","price":"1299","location":"Ghaziabad","rating":"4","photoUrl":"asdf"},{"houseName":"Second House","price":"999","location":"Ghaziabad","rating":"4","photoUrl":"asdf"}] -------------------------------------------------------------------------------- /Chapter 13 - MVC/models/home.js: -------------------------------------------------------------------------------- 1 | // Core Modules 2 | const fs = require("fs"); 3 | const path = require("path"); 4 | const rootDir = require("../utils/pathUtil"); 5 | 6 | module.exports = class Home { 7 | constructor(houseName, price, location, rating, photoUrl) { 8 | this.houseName = houseName; 9 | this.price = price; 10 | this.location = location; 11 | this.rating = rating; 12 | this.photoUrl = photoUrl; 13 | } 14 | 15 | save() { 16 | Home.fetchAll((registeredHomes) => { 17 | registeredHomes.push(this); 18 | const homeDataPath = path.join(rootDir, "data", "homes.json"); 19 | fs.writeFile(homeDataPath, JSON.stringify(registeredHomes), (error) => { 20 | console.log("File Writing Concluded", error); 21 | }); 22 | }); 23 | } 24 | 25 | static fetchAll(callback) { 26 | const homeDataPath = path.join(rootDir, "data", "homes.json"); 27 | fs.readFile(homeDataPath, (err, data) => { 28 | callback(!err ? JSON.parse(data) : []); 29 | }); 30 | } 31 | }; 32 | -------------------------------------------------------------------------------- /Chapter 13 - MVC/nodemon.json: -------------------------------------------------------------------------------- 1 | { 2 | "watch": ["."], 3 | "ext": "js,json,ejs", 4 | "ignore": ["node_modules/", "data/"], 5 | "exec": "node app.js" 6 | } -------------------------------------------------------------------------------- /Chapter 13 - MVC/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "chapter-10---airbnb", 3 | "version": "1.0.0", 4 | "main": "index.js", 5 | "scripts": { 6 | "test": "echo \"Error: no test specified\" && exit 1", 7 | "tailwind": "tailwindcss -i ./views/input.css -o ./public/output.css --watch", 8 | "start": "nodemon app.js & npm run tailwind" 9 | }, 10 | "keywords": [], 11 | "author": "", 12 | "license": "ISC", 13 | "description": "", 14 | "devDependencies": { 15 | "autoprefixer": "^10.4.20", 16 | "nodemon": "^3.1.7", 17 | "postcss": "^8.4.47", 18 | "tailwindcss": "^3.4.13" 19 | }, 20 | "dependencies": { 21 | "body-parser": "^1.20.3", 22 | "ejs": "^3.1.10", 23 | "express": "^4.21.0" 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /Chapter 13 - MVC/public/home.css: -------------------------------------------------------------------------------- 1 | body { 2 | font-family: 'Arial', sans-serif; 3 | margin: 0; 4 | padding: 0; 5 | background-color: #f5f5f5; 6 | } 7 | 8 | header { 9 | background-color: #ff5a5f; 10 | padding: 1rem 2rem; 11 | box-shadow: 0px 2px 8px rgba(0, 0, 0, 0.1); 12 | } 13 | 14 | nav { 15 | display: flex; 16 | justify-content: space-between; 17 | align-items: center; 18 | } 19 | 20 | nav ul { 21 | list-style: none; 22 | margin: 0; 23 | padding: 0; 24 | display: flex; 25 | } 26 | 27 | nav li { 28 | margin-left: 20px; 29 | } 30 | 31 | nav a { 32 | text-decoration: none; 33 | color: white; 34 | font-weight: bold; 35 | padding: 0.5rem 1rem; 36 | border-radius: 4px; 37 | transition: background-color 0.3s ease; 38 | } 39 | 40 | nav a:hover { 41 | background-color: #e54e52; 42 | } 43 | 44 | main { 45 | text-align: center; 46 | padding: 5rem 2rem; 47 | background-color: #fff; 48 | box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1); 49 | margin: 2rem auto; 50 | max-width: 600px; 51 | border-radius: 8px; 52 | } 53 | 54 | h2 { 55 | color: #333; 56 | font-size: 2rem; 57 | } -------------------------------------------------------------------------------- /Chapter 13 - MVC/routes/hostRouter.js: -------------------------------------------------------------------------------- 1 | // External Module 2 | const express = require("express"); 3 | const hostRouter = express.Router(); 4 | 5 | // Local Module 6 | const hostController = require("../controllers/hostController"); 7 | 8 | hostRouter.get("/add-home", hostController.getAddHome); 9 | hostRouter.post("/add-home", hostController.postAddHome); 10 | hostRouter.get("/host-home-list", hostController.getHostHomes); 11 | 12 | module.exports = hostRouter; 13 | -------------------------------------------------------------------------------- /Chapter 13 - MVC/routes/storeRouter.js: -------------------------------------------------------------------------------- 1 | // External Module 2 | const express = require("express"); 3 | const storeRouter = express.Router(); 4 | 5 | // Local Module 6 | const homesController = require("../controllers/storeController"); 7 | 8 | storeRouter.get("/", homesController.getIndex); 9 | storeRouter.get("/homes", homesController.getHomes); 10 | storeRouter.get("/bookings", homesController.getBookings); 11 | storeRouter.get("/favourites", homesController.getFavouriteList); 12 | 13 | module.exports = storeRouter; 14 | -------------------------------------------------------------------------------- /Chapter 13 - MVC/tailwind.config.js: -------------------------------------------------------------------------------- 1 | /** @type {import('tailwindcss').Config} */ 2 | module.exports = { 3 | content: ["./views/**/*.{html,ejs}"], 4 | theme: { 5 | extend: {}, 6 | }, 7 | plugins: [], 8 | } 9 | 10 | -------------------------------------------------------------------------------- /Chapter 13 - MVC/utils/pathUtil.js: -------------------------------------------------------------------------------- 1 | // Core Module 2 | const path = require('path'); 3 | 4 | module.exports = path.dirname(require.main.filename); -------------------------------------------------------------------------------- /Chapter 13 - MVC/views/404.ejs: -------------------------------------------------------------------------------- 1 | <%- include('partials/head') %> 2 | 3 | 4 | <%- include('partials/nav') %> 5 |
6 |

404

7 |

Oops! Page Not Found

8 | Go Back Home 13 |
14 | 15 | 16 | -------------------------------------------------------------------------------- /Chapter 13 - MVC/views/host/addHome.ejs: -------------------------------------------------------------------------------- 1 | <%- include('../partials/head') %> 2 | 3 | 4 | <%- include('../partials/nav') %> 5 |
6 |

Register Your Home on AirBnB

7 |
8 | 13 | 18 | 23 | 28 | 33 | 34 |
35 |
36 | 37 | 38 | -------------------------------------------------------------------------------- /Chapter 13 - MVC/views/host/edit-home.ejs: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Complete-Coding/NodeJS_Complete_YouTube/8db9b052a0403ad9796cc8a66329a72a55b4f5c8/Chapter 13 - MVC/views/host/edit-home.ejs -------------------------------------------------------------------------------- /Chapter 13 - MVC/views/host/home-added.ejs: -------------------------------------------------------------------------------- 1 | <%- include('../partials/head') %> 2 | 3 | 4 | <%- include('../partials/nav') %> 5 |
6 |
7 |

Home Registered Successfully

8 |

Your home has been added to our listings.

9 | Return to Home 10 |
11 |
12 | 13 | 14 | -------------------------------------------------------------------------------- /Chapter 13 - MVC/views/input.css: -------------------------------------------------------------------------------- 1 | @tailwind base; 2 | @tailwind components; 3 | @tailwind utilities; -------------------------------------------------------------------------------- /Chapter 13 - MVC/views/partials/head.ejs: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | <%= pageTitle %> 7 | -------------------------------------------------------------------------------- /Chapter 13 - MVC/views/partials/nav.ejs: -------------------------------------------------------------------------------- 1 |
2 | 48 |
-------------------------------------------------------------------------------- /Chapter 13 - MVC/views/store/bookings.ejs: -------------------------------------------------------------------------------- 1 | <%- include('../partials/head') %> 2 | 3 | 4 | <%- include('../partials/nav') %> 5 |
6 |

My Bookings

7 |

Bookings will appear here

8 |
9 | 10 | 11 | -------------------------------------------------------------------------------- /Chapter 13 - MVC/views/store/home-detail.ejs: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Complete-Coding/NodeJS_Complete_YouTube/8db9b052a0403ad9796cc8a66329a72a55b4f5c8/Chapter 13 - MVC/views/store/home-detail.ejs -------------------------------------------------------------------------------- /Chapter 13 - MVC/views/store/reserve.ejs: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Complete-Coding/NodeJS_Complete_YouTube/8db9b052a0403ad9796cc8a66329a72a55b4f5c8/Chapter 13 - MVC/views/store/reserve.ejs -------------------------------------------------------------------------------- /Chapter 14 - Dynamic Paths/app.js: -------------------------------------------------------------------------------- 1 | // Core Module 2 | const path = require('path'); 3 | 4 | // External Module 5 | const express = require('express'); 6 | 7 | //Local Module 8 | const storeRouter = require("./routes/storeRouter") 9 | const hostRouter = require("./routes/hostRouter") 10 | const rootDir = require("./utils/pathUtil"); 11 | const errorsController = require("./controllers/errors"); 12 | 13 | const app = express(); 14 | 15 | app.set('view engine', 'ejs'); 16 | app.set('views', 'views'); 17 | 18 | app.use(express.urlencoded()); 19 | app.use(storeRouter); 20 | app.use("/host", hostRouter); 21 | 22 | app.use(express.static(path.join(rootDir, 'public'))) 23 | 24 | app.use(errorsController.pageNotFound); 25 | 26 | const PORT = 3000; 27 | app.listen(PORT, () => { 28 | console.log(`Server running on address http://localhost:${PORT}`); 29 | }); -------------------------------------------------------------------------------- /Chapter 14 - Dynamic Paths/controllers/errors.js: -------------------------------------------------------------------------------- 1 | exports.pageNotFound = (req, res, next) => { 2 | res 3 | .status(404) 4 | .render("404", { pageTitle: "Page Not Found", currentPage: "404" }); 5 | }; 6 | -------------------------------------------------------------------------------- /Chapter 14 - Dynamic Paths/data/favourite.json: -------------------------------------------------------------------------------- 1 | ["2"] -------------------------------------------------------------------------------- /Chapter 14 - Dynamic Paths/data/homes.json: -------------------------------------------------------------------------------- 1 | [{"houseName":"Second House","price":"1999","location":"Ghaziabad","rating":"4.9","photoUrl":"/images/house5.png","id":"2"},{"houseName":"Summer Home","price":"1499","location":"Jaipur","rating":"4","photoUrl":"/images/house6.png","id":"0.3110618897485815"}] -------------------------------------------------------------------------------- /Chapter 14 - Dynamic Paths/models/favourite.js: -------------------------------------------------------------------------------- 1 | // Core Modules 2 | const fs = require("fs"); 3 | const path = require("path"); 4 | const rootDir = require("../utils/pathUtil"); 5 | 6 | const favouriteDataPath = path.join(rootDir, "data", "favourite.json"); 7 | 8 | module.exports = class Favourite { 9 | 10 | static addToFavourite(homeId, callback) { 11 | Favourite.getFavourites((favourites) => { 12 | if (favourites.includes(homeId)) { 13 | callback("Home is already marked favourite"); 14 | } else { 15 | favourites.push(homeId); 16 | fs.writeFile(favouriteDataPath, JSON.stringify(favourites), callback); 17 | } 18 | }); 19 | } 20 | 21 | static getFavourites(callback) { 22 | fs.readFile(favouriteDataPath, (err, data) => { 23 | callback(!err ? JSON.parse(data) : []); 24 | }); 25 | } 26 | 27 | static deleteById(delHomeId, callback) { 28 | Favourite.getFavourites(homeIds => { 29 | homeIds = homeIds.filter(homeId => delHomeId !== homeId); 30 | fs.writeFile(favouriteDataPath, JSON.stringify(homeIds),callback); 31 | }) 32 | } 33 | }; 34 | -------------------------------------------------------------------------------- /Chapter 14 - Dynamic Paths/models/home.js: -------------------------------------------------------------------------------- 1 | // Core Modules 2 | const fs = require("fs"); 3 | const path = require("path"); 4 | const rootDir = require("../utils/pathUtil"); 5 | const Favourite = require("./favourite"); 6 | 7 | const homeDataPath = path.join(rootDir, "data", "homes.json"); 8 | 9 | module.exports = class Home { 10 | constructor(houseName, price, location, rating, photoUrl) { 11 | this.houseName = houseName; 12 | this.price = price; 13 | this.location = location; 14 | this.rating = rating; 15 | this.photoUrl = photoUrl; 16 | } 17 | 18 | save() { 19 | Home.fetchAll((registeredHomes) => { 20 | if (this.id) { // edit home case 21 | registeredHomes = registeredHomes.map(home => 22 | home.id === this.id ? this : home); 23 | } else { // add home case 24 | this.id = Math.random().toString(); 25 | registeredHomes.push(this); 26 | } 27 | 28 | fs.writeFile(homeDataPath, JSON.stringify(registeredHomes), (error) => { 29 | console.log("File Writing Concluded", error); 30 | }); 31 | }); 32 | } 33 | 34 | static fetchAll(callback) { 35 | fs.readFile(homeDataPath, (err, data) => { 36 | callback(!err ? JSON.parse(data) : []); 37 | }); 38 | } 39 | 40 | static findById(homeId, callback) { 41 | this.fetchAll(homes => { 42 | const homeFound = homes.find(home => home.id === homeId); 43 | callback(homeFound); 44 | }) 45 | } 46 | 47 | static deleteById(homeId, callback) { 48 | this.fetchAll(homes => { 49 | homes = homes.filter(home => home.id !== homeId); 50 | fs.writeFile(homeDataPath, JSON.stringify(homes), error => { 51 | Favourite.deleteById(homeId, callback); 52 | }); 53 | }) 54 | } 55 | }; 56 | -------------------------------------------------------------------------------- /Chapter 14 - Dynamic Paths/nodemon.json: -------------------------------------------------------------------------------- 1 | { 2 | "watch": ["."], 3 | "ext": "js,json,ejs", 4 | "ignore": ["node_modules/", "data/"], 5 | "exec": "node app.js" 6 | } -------------------------------------------------------------------------------- /Chapter 14 - Dynamic Paths/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "chapter-10---airbnb", 3 | "version": "1.0.0", 4 | "main": "index.js", 5 | "scripts": { 6 | "test": "echo \"Error: no test specified\" && exit 1", 7 | "tailwind": "tailwindcss -i ./views/input.css -o ./public/output.css --watch", 8 | "start": "nodemon app.js & npm run tailwind" 9 | }, 10 | "keywords": [], 11 | "author": "", 12 | "license": "ISC", 13 | "description": "", 14 | "devDependencies": { 15 | "autoprefixer": "^10.4.20", 16 | "nodemon": "^3.1.7", 17 | "postcss": "^8.4.47", 18 | "tailwindcss": "^3.4.13" 19 | }, 20 | "dependencies": { 21 | "body-parser": "^1.20.3", 22 | "ejs": "^3.1.10", 23 | "express": "^4.21.0" 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /Chapter 14 - Dynamic Paths/public/home.css: -------------------------------------------------------------------------------- 1 | body { 2 | font-family: 'Arial', sans-serif; 3 | margin: 0; 4 | padding: 0; 5 | background-color: #f5f5f5; 6 | } 7 | 8 | header { 9 | background-color: #ff5a5f; 10 | padding: 1rem 2rem; 11 | box-shadow: 0px 2px 8px rgba(0, 0, 0, 0.1); 12 | } 13 | 14 | nav { 15 | display: flex; 16 | justify-content: space-between; 17 | align-items: center; 18 | } 19 | 20 | nav ul { 21 | list-style: none; 22 | margin: 0; 23 | padding: 0; 24 | display: flex; 25 | } 26 | 27 | nav li { 28 | margin-left: 20px; 29 | } 30 | 31 | nav a { 32 | text-decoration: none; 33 | color: white; 34 | font-weight: bold; 35 | padding: 0.5rem 1rem; 36 | border-radius: 4px; 37 | transition: background-color 0.3s ease; 38 | } 39 | 40 | nav a:hover { 41 | background-color: #e54e52; 42 | } 43 | 44 | main { 45 | text-align: center; 46 | padding: 5rem 2rem; 47 | background-color: #fff; 48 | box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1); 49 | margin: 2rem auto; 50 | max-width: 600px; 51 | border-radius: 8px; 52 | } 53 | 54 | h2 { 55 | color: #333; 56 | font-size: 2rem; 57 | } -------------------------------------------------------------------------------- /Chapter 14 - Dynamic Paths/public/images/house1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Complete-Coding/NodeJS_Complete_YouTube/8db9b052a0403ad9796cc8a66329a72a55b4f5c8/Chapter 14 - Dynamic Paths/public/images/house1.png -------------------------------------------------------------------------------- /Chapter 14 - Dynamic Paths/public/images/house2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Complete-Coding/NodeJS_Complete_YouTube/8db9b052a0403ad9796cc8a66329a72a55b4f5c8/Chapter 14 - Dynamic Paths/public/images/house2.png -------------------------------------------------------------------------------- /Chapter 14 - Dynamic Paths/public/images/house3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Complete-Coding/NodeJS_Complete_YouTube/8db9b052a0403ad9796cc8a66329a72a55b4f5c8/Chapter 14 - Dynamic Paths/public/images/house3.png -------------------------------------------------------------------------------- /Chapter 14 - Dynamic Paths/public/images/house4.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Complete-Coding/NodeJS_Complete_YouTube/8db9b052a0403ad9796cc8a66329a72a55b4f5c8/Chapter 14 - Dynamic Paths/public/images/house4.png -------------------------------------------------------------------------------- /Chapter 14 - Dynamic Paths/public/images/house5.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Complete-Coding/NodeJS_Complete_YouTube/8db9b052a0403ad9796cc8a66329a72a55b4f5c8/Chapter 14 - Dynamic Paths/public/images/house5.png -------------------------------------------------------------------------------- /Chapter 14 - Dynamic Paths/public/images/house6.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Complete-Coding/NodeJS_Complete_YouTube/8db9b052a0403ad9796cc8a66329a72a55b4f5c8/Chapter 14 - Dynamic Paths/public/images/house6.png -------------------------------------------------------------------------------- /Chapter 14 - Dynamic Paths/public/images/house7.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Complete-Coding/NodeJS_Complete_YouTube/8db9b052a0403ad9796cc8a66329a72a55b4f5c8/Chapter 14 - Dynamic Paths/public/images/house7.png -------------------------------------------------------------------------------- /Chapter 14 - Dynamic Paths/public/images/house8.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Complete-Coding/NodeJS_Complete_YouTube/8db9b052a0403ad9796cc8a66329a72a55b4f5c8/Chapter 14 - Dynamic Paths/public/images/house8.png -------------------------------------------------------------------------------- /Chapter 14 - Dynamic Paths/routes/hostRouter.js: -------------------------------------------------------------------------------- 1 | // External Module 2 | const express = require("express"); 3 | const hostRouter = express.Router(); 4 | 5 | // Local Module 6 | const hostController = require("../controllers/hostController"); 7 | 8 | hostRouter.get("/add-home", hostController.getAddHome); 9 | hostRouter.post("/add-home", hostController.postAddHome); 10 | hostRouter.get("/host-home-list", hostController.getHostHomes); 11 | hostRouter.get("/edit-home/:homeId", hostController.getEditHome); 12 | hostRouter.post("/edit-home", hostController.postEditHome); 13 | hostRouter.post("/delete-home/:homeId", hostController.postDeleteHome); 14 | 15 | module.exports = hostRouter; 16 | -------------------------------------------------------------------------------- /Chapter 14 - Dynamic Paths/routes/storeRouter.js: -------------------------------------------------------------------------------- 1 | // External Module 2 | const express = require("express"); 3 | const storeRouter = express.Router(); 4 | 5 | // Local Module 6 | const storeController = require("../controllers/storeController"); 7 | 8 | storeRouter.get("/", storeController.getIndex); 9 | storeRouter.get("/homes", storeController.getHomes); 10 | storeRouter.get("/bookings", storeController.getBookings); 11 | storeRouter.get("/favourites", storeController.getFavouriteList); 12 | 13 | storeRouter.get("/homes/:homeId", storeController.getHomeDetails); 14 | storeRouter.post("/favourites", storeController.postAddToFavourite); 15 | storeRouter.post("/favourites/delete/:homeId", storeController.postRemoveFromFavourite); 16 | 17 | module.exports = storeRouter; 18 | -------------------------------------------------------------------------------- /Chapter 14 - Dynamic Paths/tailwind.config.js: -------------------------------------------------------------------------------- 1 | /** @type {import('tailwindcss').Config} */ 2 | module.exports = { 3 | content: ["./views/**/*.{html,ejs}"], 4 | theme: { 5 | extend: {}, 6 | }, 7 | plugins: [], 8 | } 9 | 10 | -------------------------------------------------------------------------------- /Chapter 14 - Dynamic Paths/utils/pathUtil.js: -------------------------------------------------------------------------------- 1 | // Core Module 2 | const path = require('path'); 3 | 4 | module.exports = path.dirname(require.main.filename); -------------------------------------------------------------------------------- /Chapter 14 - Dynamic Paths/views/404.ejs: -------------------------------------------------------------------------------- 1 | <%- include('partials/head') %> 2 | 3 | 4 | <%- include('partials/nav') %> 5 |
6 |

404

7 |

Oops! Page Not Found

8 | Go Back Home 13 |
14 | 15 | 16 | -------------------------------------------------------------------------------- /Chapter 14 - Dynamic Paths/views/input.css: -------------------------------------------------------------------------------- 1 | @tailwind base; 2 | @tailwind components; 3 | @tailwind utilities; -------------------------------------------------------------------------------- /Chapter 14 - Dynamic Paths/views/partials/favourite.ejs: -------------------------------------------------------------------------------- 1 |
2 | 3 | 4 |
-------------------------------------------------------------------------------- /Chapter 14 - Dynamic Paths/views/partials/head.ejs: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | <%= pageTitle %> 7 | -------------------------------------------------------------------------------- /Chapter 14 - Dynamic Paths/views/partials/nav.ejs: -------------------------------------------------------------------------------- 1 |
2 | 48 |
-------------------------------------------------------------------------------- /Chapter 14 - Dynamic Paths/views/store/bookings.ejs: -------------------------------------------------------------------------------- 1 | <%- include('../partials/head') %> 2 | 3 | 4 | <%- include('../partials/nav') %> 5 |
6 |

My Bookings

7 |

Bookings will appear here

8 |
9 | 10 | 11 | -------------------------------------------------------------------------------- /Chapter 14 - Dynamic Paths/views/store/reserve.ejs: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Complete-Coding/NodeJS_Complete_YouTube/8db9b052a0403ad9796cc8a66329a72a55b4f5c8/Chapter 14 - Dynamic Paths/views/store/reserve.ejs -------------------------------------------------------------------------------- /Chapter 15 - Introduction to SQL/app.js: -------------------------------------------------------------------------------- 1 | // Core Module 2 | const path = require('path'); 3 | 4 | // External Module 5 | const express = require('express'); 6 | 7 | //Local Module 8 | const storeRouter = require("./routes/storeRouter") 9 | const hostRouter = require("./routes/hostRouter") 10 | const rootDir = require("./utils/pathUtil"); 11 | const errorsController = require("./controllers/errors"); 12 | 13 | const app = express(); 14 | 15 | app.set('view engine', 'ejs'); 16 | app.set('views', 'views'); 17 | 18 | app.use(express.urlencoded()); 19 | app.use(storeRouter); 20 | app.use("/host", hostRouter); 21 | 22 | app.use(express.static(path.join(rootDir, 'public'))) 23 | 24 | app.use(errorsController.pageNotFound); 25 | 26 | const PORT = 3000; 27 | app.listen(PORT, () => { 28 | console.log(`Server running on address http://localhost:${PORT}`); 29 | }); -------------------------------------------------------------------------------- /Chapter 15 - Introduction to SQL/controllers/errors.js: -------------------------------------------------------------------------------- 1 | exports.pageNotFound = (req, res, next) => { 2 | res 3 | .status(404) 4 | .render("404", { pageTitle: "Page Not Found", currentPage: "404" }); 5 | }; 6 | -------------------------------------------------------------------------------- /Chapter 15 - Introduction to SQL/data/favourite.json: -------------------------------------------------------------------------------- 1 | ["2"] -------------------------------------------------------------------------------- /Chapter 15 - Introduction to SQL/models/favourite.js: -------------------------------------------------------------------------------- 1 | // Core Modules 2 | const fs = require("fs"); 3 | const path = require("path"); 4 | const rootDir = require("../utils/pathUtil"); 5 | 6 | const favouriteDataPath = path.join(rootDir, "data", "favourite.json"); 7 | 8 | module.exports = class Favourite { 9 | 10 | static addToFavourite(homeId, callback) { 11 | Favourite.getFavourites((favourites) => { 12 | if (favourites.includes(homeId)) { 13 | callback("Home is already marked favourite"); 14 | } else { 15 | favourites.push(homeId); 16 | fs.writeFile(favouriteDataPath, JSON.stringify(favourites), callback); 17 | } 18 | }); 19 | } 20 | 21 | static getFavourites(callback) { 22 | fs.readFile(favouriteDataPath, (err, data) => { 23 | callback(!err ? JSON.parse(data) : []); 24 | }); 25 | } 26 | 27 | static deleteById(delHomeId, callback) { 28 | Favourite.getFavourites(homeIds => { 29 | homeIds = homeIds.filter(homeId => delHomeId !== homeId); 30 | fs.writeFile(favouriteDataPath, JSON.stringify(homeIds),callback); 31 | }) 32 | } 33 | }; 34 | -------------------------------------------------------------------------------- /Chapter 15 - Introduction to SQL/models/home.js: -------------------------------------------------------------------------------- 1 | // Core Modules 2 | const db = require("../utils/databaseUtil"); 3 | 4 | module.exports = class Home { 5 | constructor(houseName, price, location, rating, photoUrl, description, id) { 6 | this.houseName = houseName; 7 | this.price = price; 8 | this.location = location; 9 | this.rating = rating; 10 | this.photoUrl = photoUrl; 11 | this.description = description; 12 | this.id = id; 13 | } 14 | 15 | save() { 16 | if (this.id) { // update 17 | return db.execute('UPDATE homes SET houseName=?, price=?, location=?, rating=?, photoUrl=?, description=? WHERE id=?', [this.houseName, this.price, this.location, this.rating, this.photoUrl, this.description, this.id]); 18 | 19 | } else { // insert 20 | return db.execute('INSERT INTO homes (houseName, price, location, rating, photoUrl, description) VALUES (?, ?, ?, ?, ?, ?)', [this.houseName, this.price, this.location, this.rating, this.photoUrl, this.description]); 21 | } 22 | } 23 | 24 | static fetchAll() { 25 | return db.execute('SELECT * FROM homes'); 26 | } 27 | 28 | static findById(homeId) { 29 | return db.execute('SELECT * FROM homes WHERE id=?', [homeId]); 30 | } 31 | 32 | static deleteById(homeId) { 33 | return db.execute('DELETE FROM homes WHERE id=?', [homeId]); 34 | } 35 | }; 36 | -------------------------------------------------------------------------------- /Chapter 15 - Introduction to SQL/nodemon.json: -------------------------------------------------------------------------------- 1 | { 2 | "watch": ["."], 3 | "ext": "js,json,ejs", 4 | "ignore": ["node_modules/", "data/"], 5 | "exec": "node app.js" 6 | } -------------------------------------------------------------------------------- /Chapter 15 - Introduction to SQL/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "chapter-10---airbnb", 3 | "version": "1.0.0", 4 | "main": "index.js", 5 | "scripts": { 6 | "test": "echo \"Error: no test specified\" && exit 1", 7 | "tailwind": "tailwindcss -i ./views/input.css -o ./public/output.css --watch", 8 | "start": "nodemon app.js & npm run tailwind" 9 | }, 10 | "keywords": [], 11 | "author": "", 12 | "license": "ISC", 13 | "description": "", 14 | "devDependencies": { 15 | "autoprefixer": "^10.4.20", 16 | "nodemon": "^3.1.7", 17 | "postcss": "^8.4.47", 18 | "tailwindcss": "^3.4.13" 19 | }, 20 | "dependencies": { 21 | "body-parser": "^1.20.3", 22 | "ejs": "^3.1.10", 23 | "express": "^4.21.0", 24 | "mysql2": "^3.11.4" 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /Chapter 15 - Introduction to SQL/public/home.css: -------------------------------------------------------------------------------- 1 | body { 2 | font-family: 'Arial', sans-serif; 3 | margin: 0; 4 | padding: 0; 5 | background-color: #f5f5f5; 6 | } 7 | 8 | header { 9 | background-color: #ff5a5f; 10 | padding: 1rem 2rem; 11 | box-shadow: 0px 2px 8px rgba(0, 0, 0, 0.1); 12 | } 13 | 14 | nav { 15 | display: flex; 16 | justify-content: space-between; 17 | align-items: center; 18 | } 19 | 20 | nav ul { 21 | list-style: none; 22 | margin: 0; 23 | padding: 0; 24 | display: flex; 25 | } 26 | 27 | nav li { 28 | margin-left: 20px; 29 | } 30 | 31 | nav a { 32 | text-decoration: none; 33 | color: white; 34 | font-weight: bold; 35 | padding: 0.5rem 1rem; 36 | border-radius: 4px; 37 | transition: background-color 0.3s ease; 38 | } 39 | 40 | nav a:hover { 41 | background-color: #e54e52; 42 | } 43 | 44 | main { 45 | text-align: center; 46 | padding: 5rem 2rem; 47 | background-color: #fff; 48 | box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1); 49 | margin: 2rem auto; 50 | max-width: 600px; 51 | border-radius: 8px; 52 | } 53 | 54 | h2 { 55 | color: #333; 56 | font-size: 2rem; 57 | } -------------------------------------------------------------------------------- /Chapter 15 - Introduction to SQL/public/images/house1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Complete-Coding/NodeJS_Complete_YouTube/8db9b052a0403ad9796cc8a66329a72a55b4f5c8/Chapter 15 - Introduction to SQL/public/images/house1.png -------------------------------------------------------------------------------- /Chapter 15 - Introduction to SQL/public/images/house2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Complete-Coding/NodeJS_Complete_YouTube/8db9b052a0403ad9796cc8a66329a72a55b4f5c8/Chapter 15 - Introduction to SQL/public/images/house2.png -------------------------------------------------------------------------------- /Chapter 15 - Introduction to SQL/public/images/house3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Complete-Coding/NodeJS_Complete_YouTube/8db9b052a0403ad9796cc8a66329a72a55b4f5c8/Chapter 15 - Introduction to SQL/public/images/house3.png -------------------------------------------------------------------------------- /Chapter 15 - Introduction to SQL/public/images/house4.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Complete-Coding/NodeJS_Complete_YouTube/8db9b052a0403ad9796cc8a66329a72a55b4f5c8/Chapter 15 - Introduction to SQL/public/images/house4.png -------------------------------------------------------------------------------- /Chapter 15 - Introduction to SQL/public/images/house5.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Complete-Coding/NodeJS_Complete_YouTube/8db9b052a0403ad9796cc8a66329a72a55b4f5c8/Chapter 15 - Introduction to SQL/public/images/house5.png -------------------------------------------------------------------------------- /Chapter 15 - Introduction to SQL/public/images/house6.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Complete-Coding/NodeJS_Complete_YouTube/8db9b052a0403ad9796cc8a66329a72a55b4f5c8/Chapter 15 - Introduction to SQL/public/images/house6.png -------------------------------------------------------------------------------- /Chapter 15 - Introduction to SQL/public/images/house7.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Complete-Coding/NodeJS_Complete_YouTube/8db9b052a0403ad9796cc8a66329a72a55b4f5c8/Chapter 15 - Introduction to SQL/public/images/house7.png -------------------------------------------------------------------------------- /Chapter 15 - Introduction to SQL/public/images/house8.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Complete-Coding/NodeJS_Complete_YouTube/8db9b052a0403ad9796cc8a66329a72a55b4f5c8/Chapter 15 - Introduction to SQL/public/images/house8.png -------------------------------------------------------------------------------- /Chapter 15 - Introduction to SQL/routes/hostRouter.js: -------------------------------------------------------------------------------- 1 | // External Module 2 | const express = require("express"); 3 | const hostRouter = express.Router(); 4 | 5 | // Local Module 6 | const hostController = require("../controllers/hostController"); 7 | 8 | hostRouter.get("/add-home", hostController.getAddHome); 9 | hostRouter.post("/add-home", hostController.postAddHome); 10 | hostRouter.get("/host-home-list", hostController.getHostHomes); 11 | hostRouter.get("/edit-home/:homeId", hostController.getEditHome); 12 | hostRouter.post("/edit-home", hostController.postEditHome); 13 | hostRouter.post("/delete-home/:homeId", hostController.postDeleteHome); 14 | 15 | module.exports = hostRouter; 16 | -------------------------------------------------------------------------------- /Chapter 15 - Introduction to SQL/routes/storeRouter.js: -------------------------------------------------------------------------------- 1 | // External Module 2 | const express = require("express"); 3 | const storeRouter = express.Router(); 4 | 5 | // Local Module 6 | const storeController = require("../controllers/storeController"); 7 | 8 | storeRouter.get("/", storeController.getIndex); 9 | storeRouter.get("/homes", storeController.getHomes); 10 | storeRouter.get("/bookings", storeController.getBookings); 11 | storeRouter.get("/favourites", storeController.getFavouriteList); 12 | 13 | storeRouter.get("/homes/:homeId", storeController.getHomeDetails); 14 | storeRouter.post("/favourites", storeController.postAddToFavourite); 15 | storeRouter.post("/favourites/delete/:homeId", storeController.postRemoveFromFavourite); 16 | 17 | module.exports = storeRouter; 18 | -------------------------------------------------------------------------------- /Chapter 15 - Introduction to SQL/tailwind.config.js: -------------------------------------------------------------------------------- 1 | /** @type {import('tailwindcss').Config} */ 2 | module.exports = { 3 | content: ["./views/**/*.{html,ejs}"], 4 | theme: { 5 | extend: {}, 6 | }, 7 | plugins: [], 8 | } 9 | 10 | -------------------------------------------------------------------------------- /Chapter 15 - Introduction to SQL/utils/databaseUtil.js: -------------------------------------------------------------------------------- 1 | const mysql = require('mysql2'); 2 | 3 | const pool = mysql.createPool({ 4 | host: 'localhost', 5 | user: 'root', 6 | password: 'Completecoding@01', 7 | database: 'airbnb' 8 | }); 9 | 10 | module.exports = pool.promise(); -------------------------------------------------------------------------------- /Chapter 15 - Introduction to SQL/utils/pathUtil.js: -------------------------------------------------------------------------------- 1 | // Core Module 2 | const path = require('path'); 3 | 4 | module.exports = path.dirname(require.main.filename); -------------------------------------------------------------------------------- /Chapter 15 - Introduction to SQL/views/404.ejs: -------------------------------------------------------------------------------- 1 | <%- include('partials/head') %> 2 | 3 | 4 | <%- include('partials/nav') %> 5 |
6 |

404

7 |

Oops! Page Not Found

8 | Go Back Home 13 |
14 | 15 | 16 | -------------------------------------------------------------------------------- /Chapter 15 - Introduction to SQL/views/input.css: -------------------------------------------------------------------------------- 1 | @tailwind base; 2 | @tailwind components; 3 | @tailwind utilities; -------------------------------------------------------------------------------- /Chapter 15 - Introduction to SQL/views/partials/favourite.ejs: -------------------------------------------------------------------------------- 1 |
2 | 3 | 4 |
-------------------------------------------------------------------------------- /Chapter 15 - Introduction to SQL/views/partials/head.ejs: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | <%= pageTitle %> 7 | -------------------------------------------------------------------------------- /Chapter 15 - Introduction to SQL/views/partials/nav.ejs: -------------------------------------------------------------------------------- 1 |
2 | 48 |
-------------------------------------------------------------------------------- /Chapter 15 - Introduction to SQL/views/store/bookings.ejs: -------------------------------------------------------------------------------- 1 | <%- include('../partials/head') %> 2 | 3 | 4 | <%- include('../partials/nav') %> 5 |
6 |

My Bookings

7 |

Bookings will appear here

8 |
9 | 10 | 11 | -------------------------------------------------------------------------------- /Chapter 15 - Introduction to SQL/views/store/index.ejs: -------------------------------------------------------------------------------- 1 | <%- include('../partials/head') %> 2 | 3 | 4 | <%- include('../partials/nav') %> 5 |
6 |

7 | Welcome to airbnb index page: 8 |

9 |
10 | <% registeredHomes.forEach(home => { %> 11 |
12 | <%= home.houseName %> 13 |
14 |

<%= home.houseName %>

15 |

<%= home.location %>

16 |
17 | Rs<%= home.price %> / night 18 |
19 | 20 | 21 | 22 | <%= home.rating %> 23 |
24 |
25 | 26 |
27 |
28 | <% }) %> 29 |
30 |
31 | 32 | 33 | -------------------------------------------------------------------------------- /Chapter 15 - Introduction to SQL/views/store/reserve.ejs: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Complete-Coding/NodeJS_Complete_YouTube/8db9b052a0403ad9796cc8a66329a72a55b4f5c8/Chapter 15 - Introduction to SQL/views/store/reserve.ejs -------------------------------------------------------------------------------- /Chapter 16 - Introduction to MongoDB/app.js: -------------------------------------------------------------------------------- 1 | // Core Module 2 | const path = require('path'); 3 | 4 | // External Module 5 | const express = require('express'); 6 | 7 | //Local Module 8 | const storeRouter = require("./routes/storeRouter") 9 | const hostRouter = require("./routes/hostRouter") 10 | const rootDir = require("./utils/pathUtil"); 11 | const errorsController = require("./controllers/errors"); 12 | const {mongoConnect} = require('./utils/databaseUtil'); 13 | 14 | const app = express(); 15 | 16 | app.set('view engine', 'ejs'); 17 | app.set('views', 'views'); 18 | 19 | app.use(express.urlencoded()); 20 | app.use(storeRouter); 21 | app.use("/host", hostRouter); 22 | 23 | app.use(express.static(path.join(rootDir, 'public'))) 24 | 25 | app.use(errorsController.pageNotFound); 26 | 27 | const PORT = 3000; 28 | mongoConnect(() => { 29 | app.listen(PORT, () => { 30 | console.log(`Server running on address http://localhost:${PORT}`); 31 | }); 32 | }) 33 | -------------------------------------------------------------------------------- /Chapter 16 - Introduction to MongoDB/controllers/errors.js: -------------------------------------------------------------------------------- 1 | exports.pageNotFound = (req, res, next) => { 2 | res 3 | .status(404) 4 | .render("404", { pageTitle: "Page Not Found", currentPage: "404" }); 5 | }; 6 | -------------------------------------------------------------------------------- /Chapter 16 - Introduction to MongoDB/models/favourite.js: -------------------------------------------------------------------------------- 1 | const { getDB } = require("../utils/databaseUtil"); 2 | 3 | module.exports = class Favourite { 4 | constructor(houseId) { 5 | this.houseId = houseId; 6 | } 7 | 8 | save() { 9 | const db = getDB(); 10 | return db.collection('favourites').findOne({houseId: this.houseId}).then(existingFav => { 11 | if (!existingFav) { 12 | return db.collection('favourites').insertOne(this); 13 | } 14 | return Promise.resolve(); 15 | }) 16 | } 17 | 18 | static getFavourites() { 19 | const db = getDB(); 20 | return db.collection('favourites').find().toArray(); 21 | } 22 | 23 | static deleteById(delHomeId) { 24 | const db = getDB(); 25 | return db.collection('favourites').deleteOne({houseId: delHomeId}); 26 | } 27 | }; 28 | -------------------------------------------------------------------------------- /Chapter 16 - Introduction to MongoDB/models/home.js: -------------------------------------------------------------------------------- 1 | const { ObjectId } = require('mongodb'); 2 | const { getDB } = require('../utils/databaseUtil'); 3 | 4 | module.exports = class Home { 5 | constructor(houseName, price, location, rating, photoUrl, description, _id) { 6 | this.houseName = houseName; 7 | this.price = price; 8 | this.location = location; 9 | this.rating = rating; 10 | this.photoUrl = photoUrl; 11 | this.description = description; 12 | if (_id) { 13 | this._id = _id; 14 | } 15 | } 16 | 17 | save() { 18 | const db = getDB(); 19 | if (this._id) { // update 20 | const updateFields = { 21 | houseName: this.houseName, 22 | price: this.price, 23 | location: this.location, 24 | rating: this.rating, 25 | photoUrl: this.photoUrl, 26 | description: this.description 27 | }; 28 | 29 | return db.collection('homes').updateOne({_id: new ObjectId(String(this._id))}, {$set: updateFields}); 30 | } else { // insert 31 | return db.collection('homes').insertOne(this); 32 | } 33 | } 34 | 35 | static fetchAll() { 36 | const db = getDB(); 37 | return db.collection('homes').find().toArray(); 38 | } 39 | 40 | static findById(homeId) { 41 | const db = getDB(); 42 | return db.collection('homes') 43 | .find({_id: new ObjectId(String(homeId))}) 44 | .next(); 45 | } 46 | 47 | static deleteById(homeId) { 48 | const db = getDB(); 49 | return db.collection('homes') 50 | .deleteOne({_id: new ObjectId(String(homeId))}); 51 | } 52 | }; 53 | -------------------------------------------------------------------------------- /Chapter 16 - Introduction to MongoDB/nodemon.json: -------------------------------------------------------------------------------- 1 | { 2 | "watch": ["."], 3 | "ext": "js,json,ejs", 4 | "ignore": ["node_modules/", "data/"], 5 | "exec": "node app.js" 6 | } -------------------------------------------------------------------------------- /Chapter 16 - Introduction to MongoDB/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "chapter-10---airbnb", 3 | "version": "1.0.0", 4 | "main": "index.js", 5 | "scripts": { 6 | "test": "echo \"Error: no test specified\" && exit 1", 7 | "tailwind": "tailwindcss -i ./views/input.css -o ./public/output.css --watch", 8 | "start": "nodemon app.js & npm run tailwind" 9 | }, 10 | "keywords": [], 11 | "author": "", 12 | "license": "ISC", 13 | "description": "", 14 | "devDependencies": { 15 | "autoprefixer": "^10.4.20", 16 | "nodemon": "^3.1.7", 17 | "postcss": "^8.4.47", 18 | "tailwindcss": "^3.4.13" 19 | }, 20 | "dependencies": { 21 | "body-parser": "^1.20.3", 22 | "ejs": "^3.1.10", 23 | "express": "^4.21.0", 24 | "mongodb": "^6.10.0", 25 | "mysql2": "^3.11.4" 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /Chapter 16 - Introduction to MongoDB/public/home.css: -------------------------------------------------------------------------------- 1 | body { 2 | font-family: 'Arial', sans-serif; 3 | margin: 0; 4 | padding: 0; 5 | background-color: #f5f5f5; 6 | } 7 | 8 | header { 9 | background-color: #ff5a5f; 10 | padding: 1rem 2rem; 11 | box-shadow: 0px 2px 8px rgba(0, 0, 0, 0.1); 12 | } 13 | 14 | nav { 15 | display: flex; 16 | justify-content: space-between; 17 | align-items: center; 18 | } 19 | 20 | nav ul { 21 | list-style: none; 22 | margin: 0; 23 | padding: 0; 24 | display: flex; 25 | } 26 | 27 | nav li { 28 | margin-left: 20px; 29 | } 30 | 31 | nav a { 32 | text-decoration: none; 33 | color: white; 34 | font-weight: bold; 35 | padding: 0.5rem 1rem; 36 | border-radius: 4px; 37 | transition: background-color 0.3s ease; 38 | } 39 | 40 | nav a:hover { 41 | background-color: #e54e52; 42 | } 43 | 44 | main { 45 | text-align: center; 46 | padding: 5rem 2rem; 47 | background-color: #fff; 48 | box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1); 49 | margin: 2rem auto; 50 | max-width: 600px; 51 | border-radius: 8px; 52 | } 53 | 54 | h2 { 55 | color: #333; 56 | font-size: 2rem; 57 | } -------------------------------------------------------------------------------- /Chapter 16 - Introduction to MongoDB/public/images/house1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Complete-Coding/NodeJS_Complete_YouTube/8db9b052a0403ad9796cc8a66329a72a55b4f5c8/Chapter 16 - Introduction to MongoDB/public/images/house1.png -------------------------------------------------------------------------------- /Chapter 16 - Introduction to MongoDB/public/images/house2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Complete-Coding/NodeJS_Complete_YouTube/8db9b052a0403ad9796cc8a66329a72a55b4f5c8/Chapter 16 - Introduction to MongoDB/public/images/house2.png -------------------------------------------------------------------------------- /Chapter 16 - Introduction to MongoDB/public/images/house3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Complete-Coding/NodeJS_Complete_YouTube/8db9b052a0403ad9796cc8a66329a72a55b4f5c8/Chapter 16 - Introduction to MongoDB/public/images/house3.png -------------------------------------------------------------------------------- /Chapter 16 - Introduction to MongoDB/public/images/house4.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Complete-Coding/NodeJS_Complete_YouTube/8db9b052a0403ad9796cc8a66329a72a55b4f5c8/Chapter 16 - Introduction to MongoDB/public/images/house4.png -------------------------------------------------------------------------------- /Chapter 16 - Introduction to MongoDB/public/images/house5.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Complete-Coding/NodeJS_Complete_YouTube/8db9b052a0403ad9796cc8a66329a72a55b4f5c8/Chapter 16 - Introduction to MongoDB/public/images/house5.png -------------------------------------------------------------------------------- /Chapter 16 - Introduction to MongoDB/public/images/house6.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Complete-Coding/NodeJS_Complete_YouTube/8db9b052a0403ad9796cc8a66329a72a55b4f5c8/Chapter 16 - Introduction to MongoDB/public/images/house6.png -------------------------------------------------------------------------------- /Chapter 16 - Introduction to MongoDB/public/images/house7.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Complete-Coding/NodeJS_Complete_YouTube/8db9b052a0403ad9796cc8a66329a72a55b4f5c8/Chapter 16 - Introduction to MongoDB/public/images/house7.png -------------------------------------------------------------------------------- /Chapter 16 - Introduction to MongoDB/public/images/house8.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Complete-Coding/NodeJS_Complete_YouTube/8db9b052a0403ad9796cc8a66329a72a55b4f5c8/Chapter 16 - Introduction to MongoDB/public/images/house8.png -------------------------------------------------------------------------------- /Chapter 16 - Introduction to MongoDB/routes/hostRouter.js: -------------------------------------------------------------------------------- 1 | // External Module 2 | const express = require("express"); 3 | const hostRouter = express.Router(); 4 | 5 | // Local Module 6 | const hostController = require("../controllers/hostController"); 7 | 8 | hostRouter.get("/add-home", hostController.getAddHome); 9 | hostRouter.post("/add-home", hostController.postAddHome); 10 | hostRouter.get("/host-home-list", hostController.getHostHomes); 11 | hostRouter.get("/edit-home/:homeId", hostController.getEditHome); 12 | hostRouter.post("/edit-home", hostController.postEditHome); 13 | hostRouter.post("/delete-home/:homeId", hostController.postDeleteHome); 14 | 15 | module.exports = hostRouter; 16 | -------------------------------------------------------------------------------- /Chapter 16 - Introduction to MongoDB/routes/storeRouter.js: -------------------------------------------------------------------------------- 1 | // External Module 2 | const express = require("express"); 3 | const storeRouter = express.Router(); 4 | 5 | // Local Module 6 | const storeController = require("../controllers/storeController"); 7 | 8 | storeRouter.get("/", storeController.getIndex); 9 | storeRouter.get("/homes", storeController.getHomes); 10 | storeRouter.get("/bookings", storeController.getBookings); 11 | storeRouter.get("/favourites", storeController.getFavouriteList); 12 | 13 | storeRouter.get("/homes/:homeId", storeController.getHomeDetails); 14 | storeRouter.post("/favourites", storeController.postAddToFavourite); 15 | storeRouter.post("/favourites/delete/:homeId", storeController.postRemoveFromFavourite); 16 | 17 | module.exports = storeRouter; 18 | -------------------------------------------------------------------------------- /Chapter 16 - Introduction to MongoDB/tailwind.config.js: -------------------------------------------------------------------------------- 1 | /** @type {import('tailwindcss').Config} */ 2 | module.exports = { 3 | content: ["./views/**/*.{html,ejs}"], 4 | theme: { 5 | extend: {}, 6 | }, 7 | plugins: [], 8 | } 9 | 10 | -------------------------------------------------------------------------------- /Chapter 16 - Introduction to MongoDB/utils/databaseUtil.js: -------------------------------------------------------------------------------- 1 | const mongo = require('mongodb'); 2 | 3 | const MongoClient = mongo.MongoClient; 4 | 5 | const MONGO_URL = "mongodb+srv://root:root@completecoding.u1asz.mongodb.net/?retryWrites=true&w=majority&appName=CompleteCoding"; 6 | 7 | let _db; 8 | 9 | const mongoConnect = (callback) => { 10 | MongoClient.connect(MONGO_URL) 11 | .then(client => { 12 | callback(); 13 | _db = client.db('airbnb'); 14 | }).catch(err => { 15 | console.log('Error while connecting to Mongo: ', err); 16 | }); 17 | } 18 | 19 | const getDB = () => { 20 | if (!_db) { 21 | throw new Error('Mongo not connected'); 22 | } 23 | return _db; 24 | } 25 | 26 | exports.mongoConnect = mongoConnect; 27 | exports.getDB = getDB; -------------------------------------------------------------------------------- /Chapter 16 - Introduction to MongoDB/utils/pathUtil.js: -------------------------------------------------------------------------------- 1 | // Core Module 2 | const path = require('path'); 3 | 4 | module.exports = path.dirname(require.main.filename); -------------------------------------------------------------------------------- /Chapter 16 - Introduction to MongoDB/views/404.ejs: -------------------------------------------------------------------------------- 1 | <%- include('partials/head') %> 2 | 3 | 4 | <%- include('partials/nav') %> 5 |
6 |

404

7 |

Oops! Page Not Found

8 | Go Back Home 13 |
14 | 15 | 16 | -------------------------------------------------------------------------------- /Chapter 16 - Introduction to MongoDB/views/input.css: -------------------------------------------------------------------------------- 1 | @tailwind base; 2 | @tailwind components; 3 | @tailwind utilities; -------------------------------------------------------------------------------- /Chapter 16 - Introduction to MongoDB/views/partials/favourite.ejs: -------------------------------------------------------------------------------- 1 |
2 | 5 | 6 |
7 | -------------------------------------------------------------------------------- /Chapter 16 - Introduction to MongoDB/views/partials/head.ejs: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | <%= pageTitle %> 7 | -------------------------------------------------------------------------------- /Chapter 16 - Introduction to MongoDB/views/partials/nav.ejs: -------------------------------------------------------------------------------- 1 |
2 | 48 |
-------------------------------------------------------------------------------- /Chapter 16 - Introduction to MongoDB/views/store/bookings.ejs: -------------------------------------------------------------------------------- 1 | <%- include('../partials/head') %> 2 | 3 | 4 | <%- include('../partials/nav') %> 5 |
6 |

My Bookings

7 |

Bookings will appear here

8 |
9 | 10 | 11 | -------------------------------------------------------------------------------- /Chapter 16 - Introduction to MongoDB/views/store/index.ejs: -------------------------------------------------------------------------------- 1 | <%- include('../partials/head') %> 2 | 3 | 4 | <%- include('../partials/nav') %> 5 |
6 |

7 | Welcome to airbnb index page: 8 |

9 |
10 | <% registeredHomes.forEach(home => { %> 11 |
12 | <%= home.houseName %> 13 |
14 |

<%= home.houseName %>

15 |

<%= home.location %>

16 |
17 | Rs<%= home.price %> / night 18 |
19 | 20 | 21 | 22 | <%= home.rating %> 23 |
24 |
25 | 26 |
27 |
28 | <% }) %> 29 |
30 |
31 | 32 | 33 | -------------------------------------------------------------------------------- /Chapter 16 - Introduction to MongoDB/views/store/reserve.ejs: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Complete-Coding/NodeJS_Complete_YouTube/8db9b052a0403ad9796cc8a66329a72a55b4f5c8/Chapter 16 - Introduction to MongoDB/views/store/reserve.ejs -------------------------------------------------------------------------------- /Chapter 17 - Introduction to Mongoose/app.js: -------------------------------------------------------------------------------- 1 | // Core Module 2 | const path = require('path'); 3 | 4 | // External Module 5 | const express = require('express'); 6 | 7 | //Local Module 8 | const storeRouter = require("./routes/storeRouter") 9 | const hostRouter = require("./routes/hostRouter") 10 | const rootDir = require("./utils/pathUtil"); 11 | const errorsController = require("./controllers/errors"); 12 | const { default: mongoose } = require('mongoose'); 13 | 14 | const app = express(); 15 | 16 | app.set('view engine', 'ejs'); 17 | app.set('views', 'views'); 18 | 19 | app.use(express.urlencoded()); 20 | app.use(storeRouter); 21 | app.use("/host", hostRouter); 22 | 23 | app.use(express.static(path.join(rootDir, 'public'))) 24 | 25 | app.use(errorsController.pageNotFound); 26 | 27 | const PORT = 3000; 28 | const DB_PATH = "mongodb+srv://root:root@completecoding.u1asz.mongodb.net/airbnb?retryWrites=true&w=majority&appName=CompleteCoding"; 29 | 30 | mongoose.connect(DB_PATH).then(() => { 31 | console.log('Connected to Mongo'); 32 | app.listen(PORT, () => { 33 | console.log(`Server running on address http://localhost:${PORT}`); 34 | }); 35 | }).catch(err => { 36 | console.log('Error while connecting to Mongo: ', err); 37 | }); 38 | -------------------------------------------------------------------------------- /Chapter 17 - Introduction to Mongoose/controllers/errors.js: -------------------------------------------------------------------------------- 1 | exports.pageNotFound = (req, res, next) => { 2 | res 3 | .status(404) 4 | .render("404", { pageTitle: "Page Not Found", currentPage: "404" }); 5 | }; 6 | -------------------------------------------------------------------------------- /Chapter 17 - Introduction to Mongoose/models/favourite.js: -------------------------------------------------------------------------------- 1 | const mongoose = require('mongoose'); 2 | 3 | const favouriteSchema = mongoose.Schema({ 4 | houseId: { 5 | type: mongoose.Schema.Types.ObjectId, 6 | ref: 'Home', 7 | required: true, 8 | unique: true 9 | } 10 | }); 11 | 12 | module.exports = mongoose.model('Favourite', favouriteSchema); -------------------------------------------------------------------------------- /Chapter 17 - Introduction to Mongoose/models/home.js: -------------------------------------------------------------------------------- 1 | const mongoose = require('mongoose'); 2 | const favourite = require('./favourite'); 3 | 4 | const homeSchema = mongoose.Schema({ 5 | houseName: { 6 | type: String, 7 | required: true 8 | }, 9 | price: { 10 | type: Number, 11 | required: true 12 | }, 13 | location: { 14 | type: String, 15 | required: true 16 | }, 17 | rating: { 18 | type: Number, 19 | required: true 20 | }, 21 | photoUrl: String, 22 | description: String, 23 | }); 24 | 25 | homeSchema.pre('findOneAndDelete', async function(next) { 26 | console.log('Came to pre hook while deleting a home'); 27 | const homeId = this.getQuery()._id; 28 | await favourite.deleteMany({houseId: homeId}); 29 | next(); 30 | }); 31 | 32 | module.exports = mongoose.model('Home', homeSchema); 33 | -------------------------------------------------------------------------------- /Chapter 17 - Introduction to Mongoose/nodemon.json: -------------------------------------------------------------------------------- 1 | { 2 | "watch": ["."], 3 | "ext": "js,json,ejs", 4 | "ignore": ["node_modules/", "data/"], 5 | "exec": "node app.js" 6 | } -------------------------------------------------------------------------------- /Chapter 17 - Introduction to Mongoose/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "chapter-10---airbnb", 3 | "version": "1.0.0", 4 | "main": "index.js", 5 | "scripts": { 6 | "test": "echo \"Error: no test specified\" && exit 1", 7 | "tailwind": "tailwindcss -i ./views/input.css -o ./public/output.css --watch", 8 | "start": "nodemon app.js & npm run tailwind" 9 | }, 10 | "keywords": [], 11 | "author": "", 12 | "license": "ISC", 13 | "description": "", 14 | "devDependencies": { 15 | "autoprefixer": "^10.4.20", 16 | "nodemon": "^3.1.7", 17 | "postcss": "^8.4.47", 18 | "tailwindcss": "^3.4.13" 19 | }, 20 | "dependencies": { 21 | "body-parser": "^1.20.3", 22 | "ejs": "^3.1.10", 23 | "express": "^4.21.0", 24 | "mongodb": "^6.10.0", 25 | "mongoose": "^8.12.1", 26 | "mysql2": "^3.11.4" 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /Chapter 17 - Introduction to Mongoose/public/home.css: -------------------------------------------------------------------------------- 1 | body { 2 | font-family: 'Arial', sans-serif; 3 | margin: 0; 4 | padding: 0; 5 | background-color: #f5f5f5; 6 | } 7 | 8 | header { 9 | background-color: #ff5a5f; 10 | padding: 1rem 2rem; 11 | box-shadow: 0px 2px 8px rgba(0, 0, 0, 0.1); 12 | } 13 | 14 | nav { 15 | display: flex; 16 | justify-content: space-between; 17 | align-items: center; 18 | } 19 | 20 | nav ul { 21 | list-style: none; 22 | margin: 0; 23 | padding: 0; 24 | display: flex; 25 | } 26 | 27 | nav li { 28 | margin-left: 20px; 29 | } 30 | 31 | nav a { 32 | text-decoration: none; 33 | color: white; 34 | font-weight: bold; 35 | padding: 0.5rem 1rem; 36 | border-radius: 4px; 37 | transition: background-color 0.3s ease; 38 | } 39 | 40 | nav a:hover { 41 | background-color: #e54e52; 42 | } 43 | 44 | main { 45 | text-align: center; 46 | padding: 5rem 2rem; 47 | background-color: #fff; 48 | box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1); 49 | margin: 2rem auto; 50 | max-width: 600px; 51 | border-radius: 8px; 52 | } 53 | 54 | h2 { 55 | color: #333; 56 | font-size: 2rem; 57 | } -------------------------------------------------------------------------------- /Chapter 17 - Introduction to Mongoose/public/images/house1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Complete-Coding/NodeJS_Complete_YouTube/8db9b052a0403ad9796cc8a66329a72a55b4f5c8/Chapter 17 - Introduction to Mongoose/public/images/house1.png -------------------------------------------------------------------------------- /Chapter 17 - Introduction to Mongoose/public/images/house2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Complete-Coding/NodeJS_Complete_YouTube/8db9b052a0403ad9796cc8a66329a72a55b4f5c8/Chapter 17 - Introduction to Mongoose/public/images/house2.png -------------------------------------------------------------------------------- /Chapter 17 - Introduction to Mongoose/public/images/house3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Complete-Coding/NodeJS_Complete_YouTube/8db9b052a0403ad9796cc8a66329a72a55b4f5c8/Chapter 17 - Introduction to Mongoose/public/images/house3.png -------------------------------------------------------------------------------- /Chapter 17 - Introduction to Mongoose/public/images/house4.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Complete-Coding/NodeJS_Complete_YouTube/8db9b052a0403ad9796cc8a66329a72a55b4f5c8/Chapter 17 - Introduction to Mongoose/public/images/house4.png -------------------------------------------------------------------------------- /Chapter 17 - Introduction to Mongoose/public/images/house5.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Complete-Coding/NodeJS_Complete_YouTube/8db9b052a0403ad9796cc8a66329a72a55b4f5c8/Chapter 17 - Introduction to Mongoose/public/images/house5.png -------------------------------------------------------------------------------- /Chapter 17 - Introduction to Mongoose/public/images/house6.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Complete-Coding/NodeJS_Complete_YouTube/8db9b052a0403ad9796cc8a66329a72a55b4f5c8/Chapter 17 - Introduction to Mongoose/public/images/house6.png -------------------------------------------------------------------------------- /Chapter 17 - Introduction to Mongoose/public/images/house7.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Complete-Coding/NodeJS_Complete_YouTube/8db9b052a0403ad9796cc8a66329a72a55b4f5c8/Chapter 17 - Introduction to Mongoose/public/images/house7.png -------------------------------------------------------------------------------- /Chapter 17 - Introduction to Mongoose/public/images/house8.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Complete-Coding/NodeJS_Complete_YouTube/8db9b052a0403ad9796cc8a66329a72a55b4f5c8/Chapter 17 - Introduction to Mongoose/public/images/house8.png -------------------------------------------------------------------------------- /Chapter 17 - Introduction to Mongoose/routes/hostRouter.js: -------------------------------------------------------------------------------- 1 | // External Module 2 | const express = require("express"); 3 | const hostRouter = express.Router(); 4 | 5 | // Local Module 6 | const hostController = require("../controllers/hostController"); 7 | 8 | hostRouter.get("/add-home", hostController.getAddHome); 9 | hostRouter.post("/add-home", hostController.postAddHome); 10 | hostRouter.get("/host-home-list", hostController.getHostHomes); 11 | hostRouter.get("/edit-home/:homeId", hostController.getEditHome); 12 | hostRouter.post("/edit-home", hostController.postEditHome); 13 | hostRouter.post("/delete-home/:homeId", hostController.postDeleteHome); 14 | 15 | module.exports = hostRouter; 16 | -------------------------------------------------------------------------------- /Chapter 17 - Introduction to Mongoose/routes/storeRouter.js: -------------------------------------------------------------------------------- 1 | // External Module 2 | const express = require("express"); 3 | const storeRouter = express.Router(); 4 | 5 | // Local Module 6 | const storeController = require("../controllers/storeController"); 7 | 8 | storeRouter.get("/", storeController.getIndex); 9 | storeRouter.get("/homes", storeController.getHomes); 10 | storeRouter.get("/bookings", storeController.getBookings); 11 | storeRouter.get("/favourites", storeController.getFavouriteList); 12 | 13 | storeRouter.get("/homes/:homeId", storeController.getHomeDetails); 14 | storeRouter.post("/favourites", storeController.postAddToFavourite); 15 | storeRouter.post("/favourites/delete/:homeId", storeController.postRemoveFromFavourite); 16 | 17 | module.exports = storeRouter; 18 | -------------------------------------------------------------------------------- /Chapter 17 - Introduction to Mongoose/tailwind.config.js: -------------------------------------------------------------------------------- 1 | /** @type {import('tailwindcss').Config} */ 2 | module.exports = { 3 | content: ["./views/**/*.{html,ejs}"], 4 | theme: { 5 | extend: {}, 6 | }, 7 | plugins: [], 8 | } 9 | 10 | -------------------------------------------------------------------------------- /Chapter 17 - Introduction to Mongoose/utils/pathUtil.js: -------------------------------------------------------------------------------- 1 | // Core Module 2 | const path = require('path'); 3 | 4 | module.exports = path.dirname(require.main.filename); -------------------------------------------------------------------------------- /Chapter 17 - Introduction to Mongoose/views/404.ejs: -------------------------------------------------------------------------------- 1 | <%- include('partials/head') %> 2 | 3 | 4 | <%- include('partials/nav') %> 5 |
6 |

404

7 |

Oops! Page Not Found

8 | Go Back Home 13 |
14 | 15 | 16 | -------------------------------------------------------------------------------- /Chapter 17 - Introduction to Mongoose/views/input.css: -------------------------------------------------------------------------------- 1 | @tailwind base; 2 | @tailwind components; 3 | @tailwind utilities; -------------------------------------------------------------------------------- /Chapter 17 - Introduction to Mongoose/views/partials/favourite.ejs: -------------------------------------------------------------------------------- 1 |
2 | 5 | 6 |
7 | -------------------------------------------------------------------------------- /Chapter 17 - Introduction to Mongoose/views/partials/head.ejs: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | <%= pageTitle %> 7 | -------------------------------------------------------------------------------- /Chapter 17 - Introduction to Mongoose/views/partials/nav.ejs: -------------------------------------------------------------------------------- 1 |
2 | 48 |
-------------------------------------------------------------------------------- /Chapter 17 - Introduction to Mongoose/views/store/bookings.ejs: -------------------------------------------------------------------------------- 1 | <%- include('../partials/head') %> 2 | 3 | 4 | <%- include('../partials/nav') %> 5 |
6 |

My Bookings

7 |

Bookings will appear here

8 |
9 | 10 | 11 | -------------------------------------------------------------------------------- /Chapter 17 - Introduction to Mongoose/views/store/reserve.ejs: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Complete-Coding/NodeJS_Complete_YouTube/8db9b052a0403ad9796cc8a66329a72a55b4f5c8/Chapter 17 - Introduction to Mongoose/views/store/reserve.ejs -------------------------------------------------------------------------------- /Chapter 18 - Cookies and Sessions/app.js: -------------------------------------------------------------------------------- 1 | // Core Module 2 | const path = require('path'); 3 | 4 | // External Module 5 | const express = require('express'); 6 | const session = require('express-session'); 7 | const MongoDBStore = require('connect-mongodb-session')(session); 8 | const DB_PATH = "mongodb+srv://root:root@completecoding.u1asz.mongodb.net/airbnb?retryWrites=true&w=majority&appName=CompleteCoding"; 9 | 10 | //Local Module 11 | const storeRouter = require("./routes/storeRouter") 12 | const hostRouter = require("./routes/hostRouter") 13 | const authRouter = require("./routes/authRouter") 14 | const rootDir = require("./utils/pathUtil"); 15 | const errorsController = require("./controllers/errors"); 16 | const { default: mongoose } = require('mongoose'); 17 | 18 | const app = express(); 19 | 20 | app.set('view engine', 'ejs'); 21 | app.set('views', 'views'); 22 | 23 | const store = new MongoDBStore({ 24 | uri: DB_PATH, 25 | collection: 'sessions' 26 | }); 27 | 28 | app.use(express.urlencoded()); 29 | app.use(session({ 30 | secret: "KnowledgeGate AI with Complete Coding", 31 | resave: false, 32 | saveUninitialized: true, 33 | store 34 | })); 35 | 36 | app.use((req, res, next) => { 37 | req.isLoggedIn = req.session.isLoggedIn 38 | next(); 39 | }) 40 | 41 | app.use(authRouter) 42 | app.use(storeRouter); 43 | app.use("/host", (req, res, next) => { 44 | if (req.isLoggedIn) { 45 | next(); 46 | } else { 47 | res.redirect("/login"); 48 | } 49 | }); 50 | app.use("/host", hostRouter); 51 | 52 | app.use(express.static(path.join(rootDir, 'public'))) 53 | 54 | app.use(errorsController.pageNotFound); 55 | 56 | const PORT = 3000; 57 | 58 | mongoose.connect(DB_PATH).then(() => { 59 | console.log('Connected to Mongo'); 60 | app.listen(PORT, () => { 61 | console.log(`Server running on address http://localhost:${PORT}`); 62 | }); 63 | }).catch(err => { 64 | console.log('Error while connecting to Mongo: ', err); 65 | }); 66 | -------------------------------------------------------------------------------- /Chapter 18 - Cookies and Sessions/controllers/authController.js: -------------------------------------------------------------------------------- 1 | exports.getLogin = (req, res, next) => { 2 | res.render("auth/login", { 3 | pageTitle: "Login", 4 | currentPage: "login", 5 | isLoggedIn: false 6 | }); 7 | }; 8 | 9 | exports.postLogin = (req, res, next) => { 10 | console.log(req.body); 11 | req.session.isLoggedIn = true; 12 | //res.cookie("isLoggedIn", true); 13 | //req.isLoggedIn = true; 14 | res.redirect("/"); 15 | } 16 | 17 | exports.postLogout = (req, res, next) => { 18 | req.session.destroy(() => { 19 | res.redirect("/login"); 20 | }) 21 | } 22 | -------------------------------------------------------------------------------- /Chapter 18 - Cookies and Sessions/controllers/errors.js: -------------------------------------------------------------------------------- 1 | exports.pageNotFound = (req, res, next) => { 2 | res 3 | .status(404) 4 | .render("404", { 5 | pageTitle: "Page Not Found", 6 | currentPage: "404", 7 | isLoggedIn: req.isLoggedIn 8 | }); 9 | }; 10 | -------------------------------------------------------------------------------- /Chapter 18 - Cookies and Sessions/models/favourite.js: -------------------------------------------------------------------------------- 1 | const mongoose = require('mongoose'); 2 | 3 | const favouriteSchema = mongoose.Schema({ 4 | houseId: { 5 | type: mongoose.Schema.Types.ObjectId, 6 | ref: 'Home', 7 | required: true, 8 | unique: true 9 | } 10 | }); 11 | 12 | module.exports = mongoose.model('Favourite', favouriteSchema); -------------------------------------------------------------------------------- /Chapter 18 - Cookies and Sessions/models/home.js: -------------------------------------------------------------------------------- 1 | const mongoose = require('mongoose'); 2 | const favourite = require('./favourite'); 3 | 4 | const homeSchema = mongoose.Schema({ 5 | houseName: { 6 | type: String, 7 | required: true 8 | }, 9 | price: { 10 | type: Number, 11 | required: true 12 | }, 13 | location: { 14 | type: String, 15 | required: true 16 | }, 17 | rating: { 18 | type: Number, 19 | required: true 20 | }, 21 | photoUrl: String, 22 | description: String, 23 | }); 24 | 25 | homeSchema.pre('findOneAndDelete', async function(next) { 26 | console.log('Came to pre hook while deleting a home'); 27 | const homeId = this.getQuery()._id; 28 | await favourite.deleteMany({houseId: homeId}); 29 | next(); 30 | }); 31 | 32 | module.exports = mongoose.model('Home', homeSchema); 33 | -------------------------------------------------------------------------------- /Chapter 18 - Cookies and Sessions/nodemon.json: -------------------------------------------------------------------------------- 1 | { 2 | "watch": ["."], 3 | "ext": "js,json,ejs", 4 | "ignore": ["node_modules/", "data/"], 5 | "exec": "node app.js" 6 | } -------------------------------------------------------------------------------- /Chapter 18 - Cookies and Sessions/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "chapter-10---airbnb", 3 | "version": "1.0.0", 4 | "main": "index.js", 5 | "scripts": { 6 | "test": "echo \"Error: no test specified\" && exit 1", 7 | "tailwind": "tailwindcss -i ./views/input.css -o ./public/output.css --watch", 8 | "start": "nodemon app.js & npm run tailwind" 9 | }, 10 | "keywords": [], 11 | "author": "", 12 | "license": "ISC", 13 | "description": "", 14 | "devDependencies": { 15 | "autoprefixer": "^10.4.20", 16 | "nodemon": "^3.1.7", 17 | "postcss": "^8.4.47", 18 | "tailwindcss": "^3.4.13" 19 | }, 20 | "dependencies": { 21 | "body-parser": "^1.20.3", 22 | "connect-mongodb-session": "^5.0.0", 23 | "ejs": "^3.1.10", 24 | "express": "^4.21.0", 25 | "express-session": "^1.18.1", 26 | "mongodb": "^6.10.0", 27 | "mongoose": "^8.12.1", 28 | "mysql2": "^3.11.4" 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /Chapter 18 - Cookies and Sessions/public/home.css: -------------------------------------------------------------------------------- 1 | body { 2 | font-family: 'Arial', sans-serif; 3 | margin: 0; 4 | padding: 0; 5 | background-color: #f5f5f5; 6 | } 7 | 8 | header { 9 | background-color: #ff5a5f; 10 | padding: 1rem 2rem; 11 | box-shadow: 0px 2px 8px rgba(0, 0, 0, 0.1); 12 | } 13 | 14 | nav { 15 | display: flex; 16 | justify-content: space-between; 17 | align-items: center; 18 | } 19 | 20 | nav ul { 21 | list-style: none; 22 | margin: 0; 23 | padding: 0; 24 | display: flex; 25 | } 26 | 27 | nav li { 28 | margin-left: 20px; 29 | } 30 | 31 | nav a { 32 | text-decoration: none; 33 | color: white; 34 | font-weight: bold; 35 | padding: 0.5rem 1rem; 36 | border-radius: 4px; 37 | transition: background-color 0.3s ease; 38 | } 39 | 40 | nav a:hover { 41 | background-color: #e54e52; 42 | } 43 | 44 | main { 45 | text-align: center; 46 | padding: 5rem 2rem; 47 | background-color: #fff; 48 | box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1); 49 | margin: 2rem auto; 50 | max-width: 600px; 51 | border-radius: 8px; 52 | } 53 | 54 | h2 { 55 | color: #333; 56 | font-size: 2rem; 57 | } -------------------------------------------------------------------------------- /Chapter 18 - Cookies and Sessions/public/images/house1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Complete-Coding/NodeJS_Complete_YouTube/8db9b052a0403ad9796cc8a66329a72a55b4f5c8/Chapter 18 - Cookies and Sessions/public/images/house1.png -------------------------------------------------------------------------------- /Chapter 18 - Cookies and Sessions/public/images/house2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Complete-Coding/NodeJS_Complete_YouTube/8db9b052a0403ad9796cc8a66329a72a55b4f5c8/Chapter 18 - Cookies and Sessions/public/images/house2.png -------------------------------------------------------------------------------- /Chapter 18 - Cookies and Sessions/public/images/house3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Complete-Coding/NodeJS_Complete_YouTube/8db9b052a0403ad9796cc8a66329a72a55b4f5c8/Chapter 18 - Cookies and Sessions/public/images/house3.png -------------------------------------------------------------------------------- /Chapter 18 - Cookies and Sessions/public/images/house4.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Complete-Coding/NodeJS_Complete_YouTube/8db9b052a0403ad9796cc8a66329a72a55b4f5c8/Chapter 18 - Cookies and Sessions/public/images/house4.png -------------------------------------------------------------------------------- /Chapter 18 - Cookies and Sessions/public/images/house5.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Complete-Coding/NodeJS_Complete_YouTube/8db9b052a0403ad9796cc8a66329a72a55b4f5c8/Chapter 18 - Cookies and Sessions/public/images/house5.png -------------------------------------------------------------------------------- /Chapter 18 - Cookies and Sessions/public/images/house6.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Complete-Coding/NodeJS_Complete_YouTube/8db9b052a0403ad9796cc8a66329a72a55b4f5c8/Chapter 18 - Cookies and Sessions/public/images/house6.png -------------------------------------------------------------------------------- /Chapter 18 - Cookies and Sessions/public/images/house7.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Complete-Coding/NodeJS_Complete_YouTube/8db9b052a0403ad9796cc8a66329a72a55b4f5c8/Chapter 18 - Cookies and Sessions/public/images/house7.png -------------------------------------------------------------------------------- /Chapter 18 - Cookies and Sessions/public/images/house8.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Complete-Coding/NodeJS_Complete_YouTube/8db9b052a0403ad9796cc8a66329a72a55b4f5c8/Chapter 18 - Cookies and Sessions/public/images/house8.png -------------------------------------------------------------------------------- /Chapter 18 - Cookies and Sessions/routes/authRouter.js: -------------------------------------------------------------------------------- 1 | // External Module 2 | const express = require("express"); 3 | const authRouter = express.Router(); 4 | 5 | // Local Module 6 | const authController = require("../controllers/authController"); 7 | 8 | authRouter.get("/login", authController.getLogin); 9 | authRouter.post("/login", authController.postLogin); 10 | authRouter.post("/logout", authController.postLogout); 11 | 12 | module.exports = authRouter; 13 | -------------------------------------------------------------------------------- /Chapter 18 - Cookies and Sessions/routes/hostRouter.js: -------------------------------------------------------------------------------- 1 | // External Module 2 | const express = require("express"); 3 | const hostRouter = express.Router(); 4 | 5 | // Local Module 6 | const hostController = require("../controllers/hostController"); 7 | 8 | hostRouter.get("/add-home", hostController.getAddHome); 9 | hostRouter.post("/add-home", hostController.postAddHome); 10 | hostRouter.get("/host-home-list", hostController.getHostHomes); 11 | hostRouter.get("/edit-home/:homeId", hostController.getEditHome); 12 | hostRouter.post("/edit-home", hostController.postEditHome); 13 | hostRouter.post("/delete-home/:homeId", hostController.postDeleteHome); 14 | 15 | module.exports = hostRouter; 16 | -------------------------------------------------------------------------------- /Chapter 18 - Cookies and Sessions/routes/storeRouter.js: -------------------------------------------------------------------------------- 1 | // External Module 2 | const express = require("express"); 3 | const storeRouter = express.Router(); 4 | 5 | // Local Module 6 | const storeController = require("../controllers/storeController"); 7 | 8 | storeRouter.get("/", storeController.getIndex); 9 | storeRouter.get("/homes", storeController.getHomes); 10 | storeRouter.get("/bookings", storeController.getBookings); 11 | storeRouter.get("/favourites", storeController.getFavouriteList); 12 | 13 | storeRouter.get("/homes/:homeId", storeController.getHomeDetails); 14 | storeRouter.post("/favourites", storeController.postAddToFavourite); 15 | storeRouter.post("/favourites/delete/:homeId", storeController.postRemoveFromFavourite); 16 | 17 | module.exports = storeRouter; 18 | -------------------------------------------------------------------------------- /Chapter 18 - Cookies and Sessions/tailwind.config.js: -------------------------------------------------------------------------------- 1 | /** @type {import('tailwindcss').Config} */ 2 | module.exports = { 3 | content: ["./views/**/*.{html,ejs}"], 4 | theme: { 5 | extend: {}, 6 | }, 7 | plugins: [], 8 | } 9 | 10 | -------------------------------------------------------------------------------- /Chapter 18 - Cookies and Sessions/utils/pathUtil.js: -------------------------------------------------------------------------------- 1 | // Core Module 2 | const path = require('path'); 3 | 4 | module.exports = path.dirname(require.main.filename); -------------------------------------------------------------------------------- /Chapter 18 - Cookies and Sessions/views/404.ejs: -------------------------------------------------------------------------------- 1 | <%- include('partials/head') %> 2 | 3 | 4 | <%- include('partials/nav') %> 5 |
6 |

404

7 |

Oops! Page Not Found

8 | Go Back Home 13 |
14 | 15 | 16 | -------------------------------------------------------------------------------- /Chapter 18 - Cookies and Sessions/views/auth/login.ejs: -------------------------------------------------------------------------------- 1 | <%- include('../partials/head') %> 2 | 3 | 4 | <%- include('../partials/nav') %> 5 |
6 |

Login with your info

7 |
8 | 14 | 20 | 21 |
22 |
23 | 24 | 25 | -------------------------------------------------------------------------------- /Chapter 18 - Cookies and Sessions/views/input.css: -------------------------------------------------------------------------------- 1 | @tailwind base; 2 | @tailwind components; 3 | @tailwind utilities; -------------------------------------------------------------------------------- /Chapter 18 - Cookies and Sessions/views/partials/favourite.ejs: -------------------------------------------------------------------------------- 1 |
2 | 5 | 6 |
7 | -------------------------------------------------------------------------------- /Chapter 18 - Cookies and Sessions/views/partials/head.ejs: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | <%= pageTitle %> 7 | -------------------------------------------------------------------------------- /Chapter 18 - Cookies and Sessions/views/store/bookings.ejs: -------------------------------------------------------------------------------- 1 | <%- include('../partials/head') %> 2 | 3 | 4 | <%- include('../partials/nav') %> 5 |
6 |

My Bookings

7 |

Bookings will appear here

8 |
9 | 10 | 11 | -------------------------------------------------------------------------------- /Chapter 18 - Cookies and Sessions/views/store/index.ejs: -------------------------------------------------------------------------------- 1 | <%- include('../partials/head') %> 2 | 3 | 4 | <%- include('../partials/nav') %> 5 |
6 |

7 | Welcome to airbnb index page: 8 |

9 |
10 | <% registeredHomes.forEach(home => { %> 11 |
12 | <%= home.houseName %> 13 |
14 |

<%= home.houseName %>

15 |

<%= home.location %>

16 |
17 | Rs<%= home.price %> / night 18 |
19 | 20 | 21 | 22 | <%= home.rating %> 23 |
24 |
25 | 26 |
27 |
28 | <% }) %> 29 |
30 |
31 | 32 | 33 | -------------------------------------------------------------------------------- /Chapter 18 - Cookies and Sessions/views/store/reserve.ejs: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Complete-Coding/NodeJS_Complete_YouTube/8db9b052a0403ad9796cc8a66329a72a55b4f5c8/Chapter 18 - Cookies and Sessions/views/store/reserve.ejs -------------------------------------------------------------------------------- /Chapter 19 - Authentication and Authorization/app.js: -------------------------------------------------------------------------------- 1 | // Core Module 2 | const path = require('path'); 3 | 4 | // External Module 5 | const express = require('express'); 6 | const session = require('express-session'); 7 | const MongoDBStore = require('connect-mongodb-session')(session); 8 | const DB_PATH = "mongodb+srv://root:root@completecoding.u1asz.mongodb.net/airbnb?retryWrites=true&w=majority&appName=CompleteCoding"; 9 | 10 | //Local Module 11 | const storeRouter = require("./routes/storeRouter") 12 | const hostRouter = require("./routes/hostRouter") 13 | const authRouter = require("./routes/authRouter") 14 | const rootDir = require("./utils/pathUtil"); 15 | const errorsController = require("./controllers/errors"); 16 | const { default: mongoose } = require('mongoose'); 17 | 18 | const app = express(); 19 | 20 | app.set('view engine', 'ejs'); 21 | app.set('views', 'views'); 22 | 23 | const store = new MongoDBStore({ 24 | uri: DB_PATH, 25 | collection: 'sessions' 26 | }); 27 | 28 | app.use(express.urlencoded()); 29 | app.use(session({ 30 | secret: "KnowledgeGate AI with Complete Coding", 31 | resave: false, 32 | saveUninitialized: true, 33 | store 34 | })); 35 | 36 | app.use((req, res, next) => { 37 | req.isLoggedIn = req.session.isLoggedIn 38 | next(); 39 | }) 40 | 41 | app.use(authRouter) 42 | app.use(storeRouter); 43 | app.use("/host", (req, res, next) => { 44 | if (req.isLoggedIn) { 45 | next(); 46 | } else { 47 | res.redirect("/login"); 48 | } 49 | }); 50 | app.use("/host", hostRouter); 51 | 52 | app.use(express.static(path.join(rootDir, 'public'))) 53 | 54 | app.use(errorsController.pageNotFound); 55 | 56 | const PORT = 3003; 57 | 58 | mongoose.connect(DB_PATH).then(() => { 59 | console.log('Connected to Mongo'); 60 | app.listen(PORT, () => { 61 | console.log(`Server running on address http://localhost:${PORT}`); 62 | }); 63 | }).catch(err => { 64 | console.log('Error while connecting to Mongo: ', err); 65 | }); 66 | -------------------------------------------------------------------------------- /Chapter 19 - Authentication and Authorization/controllers/errors.js: -------------------------------------------------------------------------------- 1 | exports.pageNotFound = (req, res, next) => { 2 | res 3 | .status(404) 4 | .render("404", { 5 | pageTitle: "Page Not Found", 6 | currentPage: "404", 7 | isLoggedIn: req.isLoggedIn, 8 | user: req.session.user, 9 | }); 10 | }; 11 | -------------------------------------------------------------------------------- /Chapter 19 - Authentication and Authorization/models/home.js: -------------------------------------------------------------------------------- 1 | const mongoose = require('mongoose'); 2 | 3 | const homeSchema = mongoose.Schema({ 4 | houseName: { 5 | type: String, 6 | required: true 7 | }, 8 | price: { 9 | type: Number, 10 | required: true 11 | }, 12 | location: { 13 | type: String, 14 | required: true 15 | }, 16 | rating: { 17 | type: Number, 18 | required: true 19 | }, 20 | photoUrl: String, 21 | description: String, 22 | }); 23 | 24 | // homeSchema.pre('findOneAndDelete', async function(next) { 25 | // console.log('Came to pre hook while deleting a home'); 26 | // const homeId = this.getQuery()._id; 27 | // await favourite.deleteMany({houseId: homeId}); 28 | // next(); 29 | // }); 30 | 31 | module.exports = mongoose.model('Home', homeSchema); 32 | -------------------------------------------------------------------------------- /Chapter 19 - Authentication and Authorization/models/user.js: -------------------------------------------------------------------------------- 1 | const mongoose = require('mongoose'); 2 | 3 | const userSchema = mongoose.Schema({ 4 | firstName: { 5 | type: String, 6 | required: [true, 'First name is required'] 7 | }, 8 | lastName: String, 9 | email: { 10 | type: String, 11 | required: [true, 'Email is required'], 12 | unique: true 13 | }, 14 | password: { 15 | type: String, 16 | required: [true, 'Password is required'] 17 | }, 18 | userType: { 19 | type: String, 20 | enum: ['guest', 'host'], 21 | default: 'guest' 22 | }, 23 | favourites: [{ 24 | type: mongoose.Schema.Types.ObjectId, 25 | ref: 'Home' 26 | }] 27 | }); 28 | 29 | module.exports = mongoose.model('User', userSchema); 30 | -------------------------------------------------------------------------------- /Chapter 19 - Authentication and Authorization/nodemon.json: -------------------------------------------------------------------------------- 1 | { 2 | "watch": ["."], 3 | "ext": "js,json,ejs", 4 | "ignore": ["node_modules/", "data/"], 5 | "exec": "node app.js" 6 | } -------------------------------------------------------------------------------- /Chapter 19 - Authentication and Authorization/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "chapter-10---airbnb", 3 | "version": "1.0.0", 4 | "main": "index.js", 5 | "scripts": { 6 | "test": "echo \"Error: no test specified\" && exit 1", 7 | "tailwind": "tailwindcss -i ./views/input.css -o ./public/output.css --watch", 8 | "start": "nodemon app.js & npm run tailwind" 9 | }, 10 | "keywords": [], 11 | "author": "", 12 | "license": "ISC", 13 | "description": "", 14 | "devDependencies": { 15 | "autoprefixer": "^10.4.20", 16 | "nodemon": "^3.1.7", 17 | "postcss": "^8.4.47", 18 | "tailwindcss": "^3.4.13" 19 | }, 20 | "dependencies": { 21 | "bcryptjs": "^3.0.2", 22 | "body-parser": "^1.20.3", 23 | "connect-mongodb-session": "^5.0.0", 24 | "ejs": "^3.1.10", 25 | "express": "^4.21.0", 26 | "express-session": "^1.18.1", 27 | "express-validator": "^7.2.1", 28 | "mongodb": "^6.10.0", 29 | "mongoose": "^8.12.1", 30 | "mysql2": "^3.11.4" 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /Chapter 19 - Authentication and Authorization/public/home.css: -------------------------------------------------------------------------------- 1 | body { 2 | font-family: 'Arial', sans-serif; 3 | margin: 0; 4 | padding: 0; 5 | background-color: #f5f5f5; 6 | } 7 | 8 | header { 9 | background-color: #ff5a5f; 10 | padding: 1rem 2rem; 11 | box-shadow: 0px 2px 8px rgba(0, 0, 0, 0.1); 12 | } 13 | 14 | nav { 15 | display: flex; 16 | justify-content: space-between; 17 | align-items: center; 18 | } 19 | 20 | nav ul { 21 | list-style: none; 22 | margin: 0; 23 | padding: 0; 24 | display: flex; 25 | } 26 | 27 | nav li { 28 | margin-left: 20px; 29 | } 30 | 31 | nav a { 32 | text-decoration: none; 33 | color: white; 34 | font-weight: bold; 35 | padding: 0.5rem 1rem; 36 | border-radius: 4px; 37 | transition: background-color 0.3s ease; 38 | } 39 | 40 | nav a:hover { 41 | background-color: #e54e52; 42 | } 43 | 44 | main { 45 | text-align: center; 46 | padding: 5rem 2rem; 47 | background-color: #fff; 48 | box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1); 49 | margin: 2rem auto; 50 | max-width: 600px; 51 | border-radius: 8px; 52 | } 53 | 54 | h2 { 55 | color: #333; 56 | font-size: 2rem; 57 | } -------------------------------------------------------------------------------- /Chapter 19 - Authentication and Authorization/public/images/house1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Complete-Coding/NodeJS_Complete_YouTube/8db9b052a0403ad9796cc8a66329a72a55b4f5c8/Chapter 19 - Authentication and Authorization/public/images/house1.png -------------------------------------------------------------------------------- /Chapter 19 - Authentication and Authorization/public/images/house2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Complete-Coding/NodeJS_Complete_YouTube/8db9b052a0403ad9796cc8a66329a72a55b4f5c8/Chapter 19 - Authentication and Authorization/public/images/house2.png -------------------------------------------------------------------------------- /Chapter 19 - Authentication and Authorization/public/images/house3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Complete-Coding/NodeJS_Complete_YouTube/8db9b052a0403ad9796cc8a66329a72a55b4f5c8/Chapter 19 - Authentication and Authorization/public/images/house3.png -------------------------------------------------------------------------------- /Chapter 19 - Authentication and Authorization/public/images/house4.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Complete-Coding/NodeJS_Complete_YouTube/8db9b052a0403ad9796cc8a66329a72a55b4f5c8/Chapter 19 - Authentication and Authorization/public/images/house4.png -------------------------------------------------------------------------------- /Chapter 19 - Authentication and Authorization/public/images/house5.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Complete-Coding/NodeJS_Complete_YouTube/8db9b052a0403ad9796cc8a66329a72a55b4f5c8/Chapter 19 - Authentication and Authorization/public/images/house5.png -------------------------------------------------------------------------------- /Chapter 19 - Authentication and Authorization/public/images/house6.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Complete-Coding/NodeJS_Complete_YouTube/8db9b052a0403ad9796cc8a66329a72a55b4f5c8/Chapter 19 - Authentication and Authorization/public/images/house6.png -------------------------------------------------------------------------------- /Chapter 19 - Authentication and Authorization/public/images/house7.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Complete-Coding/NodeJS_Complete_YouTube/8db9b052a0403ad9796cc8a66329a72a55b4f5c8/Chapter 19 - Authentication and Authorization/public/images/house7.png -------------------------------------------------------------------------------- /Chapter 19 - Authentication and Authorization/public/images/house8.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Complete-Coding/NodeJS_Complete_YouTube/8db9b052a0403ad9796cc8a66329a72a55b4f5c8/Chapter 19 - Authentication and Authorization/public/images/house8.png -------------------------------------------------------------------------------- /Chapter 19 - Authentication and Authorization/routes/authRouter.js: -------------------------------------------------------------------------------- 1 | // External Module 2 | const express = require("express"); 3 | const authRouter = express.Router(); 4 | 5 | // Local Module 6 | const authController = require("../controllers/authController"); 7 | 8 | authRouter.get("/login", authController.getLogin); 9 | authRouter.post("/login", authController.postLogin); 10 | authRouter.post("/logout", authController.postLogout); 11 | authRouter.get("/signup", authController.getSignup); 12 | authRouter.post("/signup", authController.postSignup); 13 | 14 | module.exports = authRouter; 15 | -------------------------------------------------------------------------------- /Chapter 19 - Authentication and Authorization/routes/hostRouter.js: -------------------------------------------------------------------------------- 1 | // External Module 2 | const express = require("express"); 3 | const hostRouter = express.Router(); 4 | 5 | // Local Module 6 | const hostController = require("../controllers/hostController"); 7 | 8 | hostRouter.get("/add-home", hostController.getAddHome); 9 | hostRouter.post("/add-home", hostController.postAddHome); 10 | hostRouter.get("/host-home-list", hostController.getHostHomes); 11 | hostRouter.get("/edit-home/:homeId", hostController.getEditHome); 12 | hostRouter.post("/edit-home", hostController.postEditHome); 13 | hostRouter.post("/delete-home/:homeId", hostController.postDeleteHome); 14 | 15 | module.exports = hostRouter; 16 | -------------------------------------------------------------------------------- /Chapter 19 - Authentication and Authorization/routes/storeRouter.js: -------------------------------------------------------------------------------- 1 | // External Module 2 | const express = require("express"); 3 | const storeRouter = express.Router(); 4 | 5 | // Local Module 6 | const storeController = require("../controllers/storeController"); 7 | 8 | storeRouter.get("/", storeController.getIndex); 9 | storeRouter.get("/homes", storeController.getHomes); 10 | storeRouter.get("/bookings", storeController.getBookings); 11 | storeRouter.get("/favourites", storeController.getFavouriteList); 12 | 13 | storeRouter.get("/homes/:homeId", storeController.getHomeDetails); 14 | storeRouter.post("/favourites", storeController.postAddToFavourite); 15 | storeRouter.post("/favourites/delete/:homeId", storeController.postRemoveFromFavourite); 16 | 17 | module.exports = storeRouter; 18 | -------------------------------------------------------------------------------- /Chapter 19 - Authentication and Authorization/tailwind.config.js: -------------------------------------------------------------------------------- 1 | /** @type {import('tailwindcss').Config} */ 2 | module.exports = { 3 | content: ["./views/**/*.{html,ejs}"], 4 | theme: { 5 | extend: {}, 6 | }, 7 | plugins: [], 8 | } 9 | 10 | -------------------------------------------------------------------------------- /Chapter 19 - Authentication and Authorization/utils/pathUtil.js: -------------------------------------------------------------------------------- 1 | // Core Module 2 | const path = require('path'); 3 | 4 | module.exports = path.dirname(require.main.filename); -------------------------------------------------------------------------------- /Chapter 19 - Authentication and Authorization/views/404.ejs: -------------------------------------------------------------------------------- 1 | <%- include('partials/head') %> 2 | 3 | 4 | <%- include('partials/nav') %> 5 |
6 |

404

7 |

Oops! Page Not Found

8 | Go Back Home 13 |
14 | 15 | 16 | -------------------------------------------------------------------------------- /Chapter 19 - Authentication and Authorization/views/input.css: -------------------------------------------------------------------------------- 1 | @tailwind base; 2 | @tailwind components; 3 | @tailwind utilities; -------------------------------------------------------------------------------- /Chapter 19 - Authentication and Authorization/views/partials/errors.ejs: -------------------------------------------------------------------------------- 1 | <% if (errors.length > 0) {%> 2 | 13 | <% } %> -------------------------------------------------------------------------------- /Chapter 19 - Authentication and Authorization/views/partials/favourite.ejs: -------------------------------------------------------------------------------- 1 |
2 | 5 | 6 |
7 | -------------------------------------------------------------------------------- /Chapter 19 - Authentication and Authorization/views/partials/head.ejs: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | <%= pageTitle %> 7 | -------------------------------------------------------------------------------- /Chapter 19 - Authentication and Authorization/views/store/bookings.ejs: -------------------------------------------------------------------------------- 1 | <%- include('../partials/head') %> 2 | 3 | 4 | <%- include('../partials/nav') %> 5 |
6 |

My Bookings

7 |

Bookings will appear here

8 |
9 | 10 | 11 | -------------------------------------------------------------------------------- /Chapter 19 - Authentication and Authorization/views/store/reserve.ejs: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Complete-Coding/NodeJS_Complete_YouTube/8db9b052a0403ad9796cc8a66329a72a55b4f5c8/Chapter 19 - Authentication and Authorization/views/store/reserve.ejs -------------------------------------------------------------------------------- /Chapter 2 - First NodeJS Program/first.js: -------------------------------------------------------------------------------- 1 | console.log("KG Coding is the best."); 2 | 3 | const fs = require('fs'); 4 | fs.writeFile("output.txt", "Writing File", (err) => { 5 | if (err) console.log("Error occurred"); 6 | else console.log('File Written Successfully'); 7 | }); -------------------------------------------------------------------------------- /Chapter 2 - First NodeJS Program/output.txt: -------------------------------------------------------------------------------- 1 | Writing File -------------------------------------------------------------------------------- /Chapter 20 - Image Upload and Download/controllers/errors.js: -------------------------------------------------------------------------------- 1 | exports.pageNotFound = (req, res, next) => { 2 | res 3 | .status(404) 4 | .render("404", { 5 | pageTitle: "Page Not Found", 6 | currentPage: "404", 7 | isLoggedIn: req.isLoggedIn, 8 | user: req.session.user, 9 | }); 10 | }; 11 | -------------------------------------------------------------------------------- /Chapter 20 - Image Upload and Download/models/home.js: -------------------------------------------------------------------------------- 1 | const mongoose = require("mongoose"); 2 | 3 | const homeSchema = mongoose.Schema({ 4 | houseName: { 5 | type: String, 6 | required: true, 7 | }, 8 | price: { 9 | type: Number, 10 | required: true, 11 | }, 12 | location: { 13 | type: String, 14 | required: true, 15 | }, 16 | rating: { 17 | type: Number, 18 | required: true, 19 | }, 20 | photo: String, 21 | description: String, 22 | }); 23 | 24 | // homeSchema.pre('findOneAndDelete', async function(next) { 25 | // console.log('Came to pre hook while deleting a home'); 26 | // const homeId = this.getQuery()._id; 27 | // await favourite.deleteMany({houseId: homeId}); 28 | // next(); 29 | // }); 30 | 31 | module.exports = mongoose.model("Home", homeSchema); 32 | -------------------------------------------------------------------------------- /Chapter 20 - Image Upload and Download/models/user.js: -------------------------------------------------------------------------------- 1 | const mongoose = require('mongoose'); 2 | 3 | const userSchema = mongoose.Schema({ 4 | firstName: { 5 | type: String, 6 | required: [true, 'First name is required'] 7 | }, 8 | lastName: String, 9 | email: { 10 | type: String, 11 | required: [true, 'Email is required'], 12 | unique: true 13 | }, 14 | password: { 15 | type: String, 16 | required: [true, 'Password is required'] 17 | }, 18 | userType: { 19 | type: String, 20 | enum: ['guest', 'host'], 21 | default: 'guest' 22 | }, 23 | favourites: [{ 24 | type: mongoose.Schema.Types.ObjectId, 25 | ref: 'Home' 26 | }] 27 | }); 28 | 29 | module.exports = mongoose.model('User', userSchema); 30 | -------------------------------------------------------------------------------- /Chapter 20 - Image Upload and Download/nodemon.json: -------------------------------------------------------------------------------- 1 | { 2 | "watch": ["."], 3 | "ext": "js,json,ejs", 4 | "ignore": ["node_modules/", "data/"], 5 | "exec": "node app.js" 6 | } -------------------------------------------------------------------------------- /Chapter 20 - Image Upload and Download/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "chapter-10---airbnb", 3 | "version": "1.0.0", 4 | "main": "index.js", 5 | "scripts": { 6 | "test": "echo \"Error: no test specified\" && exit 1", 7 | "tailwind": "tailwindcss -i ./views/input.css -o ./public/output.css --watch", 8 | "start": "nodemon app.js & npm run tailwind" 9 | }, 10 | "keywords": [], 11 | "author": "", 12 | "license": "ISC", 13 | "description": "", 14 | "devDependencies": { 15 | "autoprefixer": "^10.4.20", 16 | "nodemon": "^3.1.7", 17 | "postcss": "^8.4.47", 18 | "tailwindcss": "^3.4.13" 19 | }, 20 | "dependencies": { 21 | "bcryptjs": "^3.0.2", 22 | "body-parser": "^1.20.3", 23 | "connect-mongodb-session": "^5.0.0", 24 | "ejs": "^3.1.10", 25 | "express": "^4.21.0", 26 | "express-session": "^1.18.1", 27 | "express-validator": "^7.2.1", 28 | "mongodb": "^6.10.0", 29 | "mongoose": "^8.12.1", 30 | "multer": "^1.4.5-lts.2", 31 | "mysql2": "^3.11.4" 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /Chapter 20 - Image Upload and Download/public/home.css: -------------------------------------------------------------------------------- 1 | body { 2 | font-family: 'Arial', sans-serif; 3 | margin: 0; 4 | padding: 0; 5 | background-color: #f5f5f5; 6 | } 7 | 8 | header { 9 | background-color: #ff5a5f; 10 | padding: 1rem 2rem; 11 | box-shadow: 0px 2px 8px rgba(0, 0, 0, 0.1); 12 | } 13 | 14 | nav { 15 | display: flex; 16 | justify-content: space-between; 17 | align-items: center; 18 | } 19 | 20 | nav ul { 21 | list-style: none; 22 | margin: 0; 23 | padding: 0; 24 | display: flex; 25 | } 26 | 27 | nav li { 28 | margin-left: 20px; 29 | } 30 | 31 | nav a { 32 | text-decoration: none; 33 | color: white; 34 | font-weight: bold; 35 | padding: 0.5rem 1rem; 36 | border-radius: 4px; 37 | transition: background-color 0.3s ease; 38 | } 39 | 40 | nav a:hover { 41 | background-color: #e54e52; 42 | } 43 | 44 | main { 45 | text-align: center; 46 | padding: 5rem 2rem; 47 | background-color: #fff; 48 | box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1); 49 | margin: 2rem auto; 50 | max-width: 600px; 51 | border-radius: 8px; 52 | } 53 | 54 | h2 { 55 | color: #333; 56 | font-size: 2rem; 57 | } -------------------------------------------------------------------------------- /Chapter 20 - Image Upload and Download/public/images/house1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Complete-Coding/NodeJS_Complete_YouTube/8db9b052a0403ad9796cc8a66329a72a55b4f5c8/Chapter 20 - Image Upload and Download/public/images/house1.png -------------------------------------------------------------------------------- /Chapter 20 - Image Upload and Download/public/images/house2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Complete-Coding/NodeJS_Complete_YouTube/8db9b052a0403ad9796cc8a66329a72a55b4f5c8/Chapter 20 - Image Upload and Download/public/images/house2.png -------------------------------------------------------------------------------- /Chapter 20 - Image Upload and Download/public/images/house3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Complete-Coding/NodeJS_Complete_YouTube/8db9b052a0403ad9796cc8a66329a72a55b4f5c8/Chapter 20 - Image Upload and Download/public/images/house3.png -------------------------------------------------------------------------------- /Chapter 20 - Image Upload and Download/public/images/house4.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Complete-Coding/NodeJS_Complete_YouTube/8db9b052a0403ad9796cc8a66329a72a55b4f5c8/Chapter 20 - Image Upload and Download/public/images/house4.png -------------------------------------------------------------------------------- /Chapter 20 - Image Upload and Download/public/images/house5.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Complete-Coding/NodeJS_Complete_YouTube/8db9b052a0403ad9796cc8a66329a72a55b4f5c8/Chapter 20 - Image Upload and Download/public/images/house5.png -------------------------------------------------------------------------------- /Chapter 20 - Image Upload and Download/public/images/house6.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Complete-Coding/NodeJS_Complete_YouTube/8db9b052a0403ad9796cc8a66329a72a55b4f5c8/Chapter 20 - Image Upload and Download/public/images/house6.png -------------------------------------------------------------------------------- /Chapter 20 - Image Upload and Download/public/images/house7.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Complete-Coding/NodeJS_Complete_YouTube/8db9b052a0403ad9796cc8a66329a72a55b4f5c8/Chapter 20 - Image Upload and Download/public/images/house7.png -------------------------------------------------------------------------------- /Chapter 20 - Image Upload and Download/public/images/house8.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Complete-Coding/NodeJS_Complete_YouTube/8db9b052a0403ad9796cc8a66329a72a55b4f5c8/Chapter 20 - Image Upload and Download/public/images/house8.png -------------------------------------------------------------------------------- /Chapter 20 - Image Upload and Download/routes/authRouter.js: -------------------------------------------------------------------------------- 1 | // External Module 2 | const express = require("express"); 3 | const authRouter = express.Router(); 4 | 5 | // Local Module 6 | const authController = require("../controllers/authController"); 7 | 8 | authRouter.get("/login", authController.getLogin); 9 | authRouter.post("/login", authController.postLogin); 10 | authRouter.post("/logout", authController.postLogout); 11 | authRouter.get("/signup", authController.getSignup); 12 | authRouter.post("/signup", authController.postSignup); 13 | 14 | module.exports = authRouter; 15 | -------------------------------------------------------------------------------- /Chapter 20 - Image Upload and Download/routes/hostRouter.js: -------------------------------------------------------------------------------- 1 | // External Module 2 | const express = require("express"); 3 | const hostRouter = express.Router(); 4 | 5 | // Local Module 6 | const hostController = require("../controllers/hostController"); 7 | 8 | hostRouter.get("/add-home", hostController.getAddHome); 9 | hostRouter.post("/add-home", hostController.postAddHome); 10 | hostRouter.get("/host-home-list", hostController.getHostHomes); 11 | hostRouter.get("/edit-home/:homeId", hostController.getEditHome); 12 | hostRouter.post("/edit-home", hostController.postEditHome); 13 | hostRouter.post("/delete-home/:homeId", hostController.postDeleteHome); 14 | 15 | module.exports = hostRouter; 16 | -------------------------------------------------------------------------------- /Chapter 20 - Image Upload and Download/routes/storeRouter.js: -------------------------------------------------------------------------------- 1 | // External Module 2 | const express = require("express"); 3 | const storeRouter = express.Router(); 4 | 5 | // Local Module 6 | const storeController = require("../controllers/storeController"); 7 | 8 | storeRouter.get("/", storeController.getIndex); 9 | storeRouter.get("/homes", storeController.getHomes); 10 | storeRouter.get("/bookings", storeController.getBookings); 11 | storeRouter.get("/favourites", storeController.getFavouriteList); 12 | 13 | storeRouter.get("/homes/:homeId", storeController.getHomeDetails); 14 | storeRouter.post("/favourites", storeController.postAddToFavourite); 15 | storeRouter.post("/favourites/delete/:homeId", storeController.postRemoveFromFavourite); 16 | 17 | module.exports = storeRouter; 18 | -------------------------------------------------------------------------------- /Chapter 20 - Image Upload and Download/tailwind.config.js: -------------------------------------------------------------------------------- 1 | /** @type {import('tailwindcss').Config} */ 2 | module.exports = { 3 | content: ["./views/**/*.{html,ejs}"], 4 | theme: { 5 | extend: {}, 6 | }, 7 | plugins: [], 8 | } 9 | 10 | -------------------------------------------------------------------------------- /Chapter 20 - Image Upload and Download/uploads/dempoltkuv-146.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Complete-Coding/NodeJS_Complete_YouTube/8db9b052a0403ad9796cc8a66329a72a55b4f5c8/Chapter 20 - Image Upload and Download/uploads/dempoltkuv-146.png -------------------------------------------------------------------------------- /Chapter 20 - Image Upload and Download/utils/pathUtil.js: -------------------------------------------------------------------------------- 1 | // Core Module 2 | const path = require('path'); 3 | 4 | module.exports = path.dirname(require.main.filename); -------------------------------------------------------------------------------- /Chapter 20 - Image Upload and Download/views/404.ejs: -------------------------------------------------------------------------------- 1 | <%- include('partials/head') %> 2 | 3 | 4 | <%- include('partials/nav') %> 5 |
6 |

404

7 |

Oops! Page Not Found

8 | Go Back Home 13 |
14 | 15 | 16 | -------------------------------------------------------------------------------- /Chapter 20 - Image Upload and Download/views/input.css: -------------------------------------------------------------------------------- 1 | @tailwind base; 2 | @tailwind components; 3 | @tailwind utilities; -------------------------------------------------------------------------------- /Chapter 20 - Image Upload and Download/views/partials/errors.ejs: -------------------------------------------------------------------------------- 1 | <% if (errors.length > 0) {%> 2 | 13 | <% } %> -------------------------------------------------------------------------------- /Chapter 20 - Image Upload and Download/views/partials/favourite.ejs: -------------------------------------------------------------------------------- 1 |
2 | 5 | 6 |
7 | -------------------------------------------------------------------------------- /Chapter 20 - Image Upload and Download/views/partials/head.ejs: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | <%= pageTitle %> 7 | -------------------------------------------------------------------------------- /Chapter 20 - Image Upload and Download/views/store/bookings.ejs: -------------------------------------------------------------------------------- 1 | <%- include('../partials/head') %> 2 | 3 | 4 | <%- include('../partials/nav') %> 5 |
6 |

My Bookings

7 |

Bookings will appear here

8 |
9 | 10 | 11 | -------------------------------------------------------------------------------- /Chapter 20 - Image Upload and Download/views/store/index.ejs: -------------------------------------------------------------------------------- 1 | <%- include('../partials/head') %> 2 | 3 | 4 | <%- include('../partials/nav') %> 5 |
6 |

7 | Welcome to airbnb index page: 8 |

9 |
10 | <% registeredHomes.forEach(home => { %> 11 |
12 | <%= home.houseName %> 13 |
14 |

<%= home.houseName %>

15 |

<%= home.location %>

16 |
17 | Rs<%= home.price %> / night 18 |
19 | 20 | 21 | 22 | <%= home.rating %> 23 |
24 |
25 | 26 |
27 |
28 | <% }) %> 29 |
30 |
31 | 32 | 33 | -------------------------------------------------------------------------------- /Chapter 20 - Image Upload and Download/views/store/reserve.ejs: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Complete-Coding/NodeJS_Complete_YouTube/8db9b052a0403ad9796cc8a66329a72a55b4f5c8/Chapter 20 - Image Upload and Download/views/store/reserve.ejs -------------------------------------------------------------------------------- /Chapter 21 - REST API and Json Requests /todo-backend/app.js: -------------------------------------------------------------------------------- 1 | // Core Module 2 | const path = require('path'); 3 | 4 | // External Module 5 | const express = require('express'); 6 | const { default: mongoose } = require('mongoose'); 7 | const cors = require('cors'); 8 | const DB_PATH = "mongodb+srv://root:root@completecoding.u1asz.mongodb.net/todo?retryWrites=true&w=majority&appName=CompleteCoding"; 9 | 10 | //Local Module 11 | const todoItemsRouter = require("./routes/todoItemsRouter") 12 | const errorsController = require("./controllers/errors"); 13 | 14 | const app = express(); 15 | 16 | app.use(express.urlencoded()); 17 | app.use(express.json()); 18 | app.use(cors()); 19 | 20 | app.use("/api/todo", todoItemsRouter); 21 | 22 | app.use(errorsController.pageNotFound); 23 | 24 | const PORT = 3001; 25 | 26 | mongoose.connect(DB_PATH).then(() => { 27 | console.log('Connected to Mongo'); 28 | app.listen(PORT, () => { 29 | console.log(`Server running on address http://localhost:${PORT}`); 30 | }); 31 | }).catch(err => { 32 | console.log('Error while connecting to Mongo: ', err); 33 | }); 34 | -------------------------------------------------------------------------------- /Chapter 21 - REST API and Json Requests /todo-backend/controllers/errors.js: -------------------------------------------------------------------------------- 1 | exports.pageNotFound = (req, res, next) => { 2 | res.status(404).json({message: "Page not found"}); 3 | }; 4 | -------------------------------------------------------------------------------- /Chapter 21 - REST API and Json Requests /todo-backend/controllers/todoItemsController.js: -------------------------------------------------------------------------------- 1 | const TodoItem = require("../models/TodoItem"); 2 | 3 | exports.createTodoItem = async (req, res, next) => { 4 | console.log(req.body); 5 | const { task, date } = req.body; 6 | const todoItem = new TodoItem({ task, date }); 7 | await todoItem.save(); 8 | res.status(201).json(todoItem); 9 | } 10 | 11 | exports.getTodoItems = async (req, res, next) => { 12 | const todoItems = await TodoItem.find(); 13 | res.json(todoItems); 14 | } 15 | 16 | exports.deleteTodoItem = async (req, res, next) => { 17 | const { id } = req.params; 18 | await TodoItem.findByIdAndDelete(id); 19 | res.status(204).json({_id: id}); 20 | } 21 | 22 | exports.markCompleted = async (req, res, next) => { 23 | const { id } = req.params; 24 | const todoItem = await TodoItem.findById(id); 25 | todoItem.completed = true; 26 | await todoItem.save(); 27 | res.json(todoItem); 28 | } -------------------------------------------------------------------------------- /Chapter 21 - REST API and Json Requests /todo-backend/models/TodoItem.js: -------------------------------------------------------------------------------- 1 | const mongoose = require("mongoose"); 2 | 3 | const todoItemSchema = mongoose.Schema( 4 | { 5 | task: { 6 | type: String, 7 | required: true, 8 | }, 9 | date: Date, 10 | completed: { 11 | type: Boolean, 12 | default: false, 13 | }, 14 | }, 15 | { timestamps: true } 16 | ); 17 | 18 | module.exports = mongoose.model("TodoItem", todoItemSchema); 19 | -------------------------------------------------------------------------------- /Chapter 21 - REST API and Json Requests /todo-backend/nodemon.json: -------------------------------------------------------------------------------- 1 | { 2 | "watch": ["."], 3 | "ext": "js,json,ejs", 4 | "ignore": ["node_modules/", "data/"], 5 | "exec": "node app.js" 6 | } -------------------------------------------------------------------------------- /Chapter 21 - REST API and Json Requests /todo-backend/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "chapter-10---airbnb", 3 | "version": "1.0.0", 4 | "main": "index.js", 5 | "scripts": { 6 | "test": "echo \"Error: no test specified\" && exit 1", 7 | "tailwind": "tailwindcss -i ./views/input.css -o ./public/output.css --watch", 8 | "start": "nodemon app.js & npm run tailwind" 9 | }, 10 | "keywords": [], 11 | "author": "", 12 | "license": "ISC", 13 | "description": "", 14 | "devDependencies": { 15 | "autoprefixer": "^10.4.20", 16 | "nodemon": "^3.1.7", 17 | "postcss": "^8.4.47", 18 | "tailwindcss": "^3.4.13" 19 | }, 20 | "dependencies": { 21 | "body-parser": "^1.20.3", 22 | "cors": "^2.8.5", 23 | "express": "^4.21.0", 24 | "express-validator": "^7.2.1", 25 | "mongodb": "^6.10.0", 26 | "mongoose": "^8.12.1" 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /Chapter 21 - REST API and Json Requests /todo-backend/public/home.css: -------------------------------------------------------------------------------- 1 | body { 2 | font-family: 'Arial', sans-serif; 3 | margin: 0; 4 | padding: 0; 5 | background-color: #f5f5f5; 6 | } 7 | 8 | header { 9 | background-color: #ff5a5f; 10 | padding: 1rem 2rem; 11 | box-shadow: 0px 2px 8px rgba(0, 0, 0, 0.1); 12 | } 13 | 14 | nav { 15 | display: flex; 16 | justify-content: space-between; 17 | align-items: center; 18 | } 19 | 20 | nav ul { 21 | list-style: none; 22 | margin: 0; 23 | padding: 0; 24 | display: flex; 25 | } 26 | 27 | nav li { 28 | margin-left: 20px; 29 | } 30 | 31 | nav a { 32 | text-decoration: none; 33 | color: white; 34 | font-weight: bold; 35 | padding: 0.5rem 1rem; 36 | border-radius: 4px; 37 | transition: background-color 0.3s ease; 38 | } 39 | 40 | nav a:hover { 41 | background-color: #e54e52; 42 | } 43 | 44 | main { 45 | text-align: center; 46 | padding: 5rem 2rem; 47 | background-color: #fff; 48 | box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1); 49 | margin: 2rem auto; 50 | max-width: 600px; 51 | border-radius: 8px; 52 | } 53 | 54 | h2 { 55 | color: #333; 56 | font-size: 2rem; 57 | } -------------------------------------------------------------------------------- /Chapter 21 - REST API and Json Requests /todo-backend/routes/todoItemsRouter.js: -------------------------------------------------------------------------------- 1 | // External Module 2 | const express = require("express"); 3 | const todoItemsRouter = express.Router(); 4 | 5 | // Local Module 6 | const todoItemsController = require("../controllers/todoItemsController"); 7 | 8 | todoItemsRouter.get("/", todoItemsController.getTodoItems); 9 | todoItemsRouter.post("/", todoItemsController.createTodoItem); 10 | todoItemsRouter.delete("/:id", todoItemsController.deleteTodoItem); 11 | todoItemsRouter.put("/:id/completed", todoItemsController.markCompleted); 12 | 13 | module.exports = todoItemsRouter; -------------------------------------------------------------------------------- /Chapter 21 - REST API and Json Requests /todo-backend/tailwind.config.js: -------------------------------------------------------------------------------- 1 | /** @type {import('tailwindcss').Config} */ 2 | module.exports = { 3 | content: ["./views/**/*.{html,ejs}"], 4 | theme: { 5 | extend: {}, 6 | }, 7 | plugins: [], 8 | } 9 | 10 | -------------------------------------------------------------------------------- /Chapter 21 - REST API and Json Requests /todo-backend/utils/pathUtil.js: -------------------------------------------------------------------------------- 1 | // Core Module 2 | const path = require('path'); 3 | 4 | module.exports = path.dirname(require.main.filename); -------------------------------------------------------------------------------- /Chapter 21 - REST API and Json Requests /todo-frontend/.eslintrc.cjs: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | root: true, 3 | env: { browser: true, es2020: true }, 4 | extends: [ 5 | 'eslint:recommended', 6 | 'plugin:react/recommended', 7 | 'plugin:react/jsx-runtime', 8 | 'plugin:react-hooks/recommended', 9 | ], 10 | ignorePatterns: ['dist', '.eslintrc.cjs'], 11 | parserOptions: { ecmaVersion: 'latest', sourceType: 'module' }, 12 | settings: { react: { version: '18.2' } }, 13 | plugins: ['react-refresh'], 14 | rules: { 15 | 'react-refresh/only-export-components': [ 16 | 'warn', 17 | { allowConstantExport: true }, 18 | ], 19 | }, 20 | } 21 | -------------------------------------------------------------------------------- /Chapter 21 - REST API and Json Requests /todo-frontend/.gitignore: -------------------------------------------------------------------------------- 1 | # Logs 2 | logs 3 | *.log 4 | npm-debug.log* 5 | yarn-debug.log* 6 | yarn-error.log* 7 | pnpm-debug.log* 8 | lerna-debug.log* 9 | 10 | node_modules 11 | dist 12 | dist-ssr 13 | *.local 14 | 15 | # Editor directories and files 16 | .vscode/* 17 | !.vscode/extensions.json 18 | .idea 19 | .DS_Store 20 | *.suo 21 | *.ntvs* 22 | *.njsproj 23 | *.sln 24 | *.sw? 25 | -------------------------------------------------------------------------------- /Chapter 21 - REST API and Json Requests /todo-frontend/README.md: -------------------------------------------------------------------------------- 1 | # React + Vite 2 | 3 | This template provides a minimal setup to get React working in Vite with HMR and some ESLint rules. 4 | 5 | Currently, two official plugins are available: 6 | 7 | - [@vitejs/plugin-react](https://github.com/vitejs/vite-plugin-react/blob/main/packages/plugin-react/README.md) uses [Babel](https://babeljs.io/) for Fast Refresh 8 | - [@vitejs/plugin-react-swc](https://github.com/vitejs/vite-plugin-react-swc) uses [SWC](https://swc.rs/) for Fast Refresh 9 | -------------------------------------------------------------------------------- /Chapter 21 - REST API and Json Requests /todo-frontend/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | Vite + React 8 | 9 | 10 |
11 | 12 | 13 | 14 | -------------------------------------------------------------------------------- /Chapter 21 - REST API and Json Requests /todo-frontend/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "1-todo-app-version-one", 3 | "private": true, 4 | "version": "0.0.0", 5 | "type": "module", 6 | "scripts": { 7 | "dev": "vite", 8 | "build": "vite build", 9 | "lint": "eslint . --ext js,jsx --report-unused-disable-directives --max-warnings 0", 10 | "preview": "vite preview" 11 | }, 12 | "dependencies": { 13 | "@tailwindcss/vite": "^4.0.15", 14 | "react": "^18.2.0", 15 | "react-dom": "^18.2.0", 16 | "tailwindcss": "^4.0.15" 17 | }, 18 | "devDependencies": { 19 | "@types/react": "^18.2.66", 20 | "@types/react-dom": "^18.2.22", 21 | "@vitejs/plugin-react": "^4.2.1", 22 | "eslint": "^8.57.0", 23 | "eslint-plugin-react": "^7.34.0", 24 | "eslint-plugin-react-hooks": "^4.6.0", 25 | "eslint-plugin-react-refresh": "^0.4.5", 26 | "vite": "^5.2.3" 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /Chapter 21 - REST API and Json Requests /todo-frontend/public/vite.svg: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /Chapter 21 - REST API and Json Requests /todo-frontend/src/App.css: -------------------------------------------------------------------------------- 1 | @import "tailwindcss"; -------------------------------------------------------------------------------- /Chapter 21 - REST API and Json Requests /todo-frontend/src/components/AddTodo.jsx: -------------------------------------------------------------------------------- 1 | import { useState } from "react"; 2 | 3 | function AddTodo({ onNewItem }) { 4 | const [todoName, setTodoName] = useState(); 5 | const [dueDate, setDueDate] = useState(); 6 | 7 | const handleNameChange = (event) => { 8 | setTodoName(event.target.value); 9 | }; 10 | 11 | const handleDateChange = (event) => { 12 | setDueDate(event.target.value); 13 | }; 14 | 15 | const handleAddButtonClicked = () => { 16 | onNewItem(todoName, dueDate); 17 | setDueDate(""); 18 | setTodoName(""); 19 | }; 20 | 21 | return ( 22 |
23 |
24 |
25 | 32 |
33 |
34 | 40 |
41 |
42 | 49 |
50 |
51 |
52 | ); 53 | } 54 | 55 | export default AddTodo; 56 | -------------------------------------------------------------------------------- /Chapter 21 - REST API and Json Requests /todo-frontend/src/components/AppName.jsx: -------------------------------------------------------------------------------- 1 | function AppName() { 2 | return ( 3 |

4 | TODO App 5 |

6 | ); 7 | } 8 | 9 | export default AppName; 10 | -------------------------------------------------------------------------------- /Chapter 21 - REST API and Json Requests /todo-frontend/src/components/TodoItem.jsx: -------------------------------------------------------------------------------- 1 | function TodoItem({ 2 | id, 3 | todoName, 4 | todoDate, 5 | completed, 6 | onDeleteClick, 7 | onToggleComplete, 8 | }) { 9 | // Format the date to show only the date part (YYYY-MM-DD) 10 | const formatDate = (dateString) => { 11 | if (!dateString) return ""; 12 | return new Date(dateString).toLocaleDateString("en-US", { 13 | year: "numeric", 14 | month: "short", 15 | day: "numeric", 16 | }); 17 | }; 18 | 19 | return ( 20 |
25 |
26 | onToggleComplete(id)} 30 | className="w-5 h-5 text-indigo-600 rounded border-gray-300 focus:ring-indigo-500 mr-3" 31 | /> 32 | 37 | {todoName} 38 | 39 |
40 |
41 | {formatDate(todoDate)} 42 |
43 |
44 | 51 |
52 |
53 | ); 54 | } 55 | 56 | export default TodoItem; 57 | -------------------------------------------------------------------------------- /Chapter 21 - REST API and Json Requests /todo-frontend/src/components/TodoItems.jsx: -------------------------------------------------------------------------------- 1 | import TodoItem from "./TodoItem"; 2 | 3 | const TodoItems = ({ todoItems, onDeleteClick, onToggleComplete }) => { 4 | // Group items by completion status 5 | const pendingItems = todoItems.filter((item) => !item.completed); 6 | const completedItems = todoItems.filter((item) => item.completed); 7 | 8 | return ( 9 |
10 | {pendingItems.length > 0 && ( 11 |
12 |

13 | Tasks to Do 14 |

15 |
16 | {pendingItems.map((item) => ( 17 | 26 | ))} 27 |
28 |
29 | )} 30 | 31 | {completedItems.length > 0 && ( 32 |
33 |

34 | Completed Tasks 35 |

36 |
37 | {completedItems.map((item) => ( 38 | 47 | ))} 48 |
49 |
50 | )} 51 |
52 | ); 53 | }; 54 | 55 | export default TodoItems; 56 | -------------------------------------------------------------------------------- /Chapter 21 - REST API and Json Requests /todo-frontend/src/components/WelcomeMessage.jsx: -------------------------------------------------------------------------------- 1 | const WelcomeMessage = () => { 2 | return ( 3 |
4 |

5 | Enjoy Your Day! Add a todo to get started. 6 |

7 |
8 | ); 9 | }; 10 | 11 | export default WelcomeMessage; 12 | -------------------------------------------------------------------------------- /Chapter 21 - REST API and Json Requests /todo-frontend/src/main.jsx: -------------------------------------------------------------------------------- 1 | import React from 'react' 2 | import ReactDOM from 'react-dom/client' 3 | import App from './App.jsx' 4 | 5 | ReactDOM.createRoot(document.getElementById('root')).render( 6 | 7 | 8 | , 9 | ) 10 | -------------------------------------------------------------------------------- /Chapter 21 - REST API and Json Requests /todo-frontend/src/services/itemsService.js: -------------------------------------------------------------------------------- 1 | export const addItemToServer = async (task, date) => { 2 | const response = await fetch("http://localhost:3001/api/todo", { 3 | method: "POST", 4 | headers: { 5 | "Content-Type": "application/json", 6 | }, 7 | body: JSON.stringify({ task, date }), 8 | }); 9 | const item = await response.json(); 10 | return mapServerItemToLocalItem(item); 11 | }; 12 | 13 | export const getItemsFromServer = async () => { 14 | const response = await fetch("http://localhost:3001/api/todo"); 15 | const items = await response.json(); 16 | return items.map(mapServerItemToLocalItem); 17 | }; 18 | 19 | export const markItemCompletedOnServer = async (id) => { 20 | const response = await fetch( 21 | `http://localhost:3001/api/todo/${id}/completed`, 22 | { 23 | method: "PUT", 24 | } 25 | ); 26 | const item = await response.json(); 27 | return mapServerItemToLocalItem(item); 28 | }; 29 | 30 | export const deleteItemFromServer = async (id) => { 31 | await fetch(`http://localhost:3001/api/todo/${id}`, { 32 | method: "DELETE", 33 | }); 34 | return id; 35 | }; 36 | 37 | const mapServerItemToLocalItem = (serverItem) => { 38 | return { 39 | id: serverItem._id, 40 | name: serverItem.task, 41 | dueDate: serverItem.date, 42 | completed: serverItem.completed, 43 | createdAt: serverItem.createdAt, 44 | updatedAt: serverItem.updatedAt, 45 | }; 46 | }; 47 | -------------------------------------------------------------------------------- /Chapter 21 - REST API and Json Requests /todo-frontend/vite.config.js: -------------------------------------------------------------------------------- 1 | import { defineConfig } from 'vite' 2 | import react from '@vitejs/plugin-react' 3 | import tailwindcss from '@tailwindcss/vite' 4 | 5 | // https://vitejs.dev/config/ 6 | export default defineConfig({ 7 | plugins: [ 8 | react(), 9 | tailwindcss(), 10 | ], 11 | }) 12 | -------------------------------------------------------------------------------- /Chapter 3 - First Node Server/app.js: -------------------------------------------------------------------------------- 1 | const http = require('http'); 2 | 3 | const server = http.createServer((req, res) => { 4 | console.log(req); 5 | }); 6 | 7 | const PORT = 3001; 8 | server.listen(PORT, () => { 9 | console.log(`Server running on address http://localhost:${PORT}`); 10 | }); -------------------------------------------------------------------------------- /Chapter 4 - Request and Reponse/app.js: -------------------------------------------------------------------------------- 1 | const http = require('http'); 2 | 3 | const server = http.createServer((req, res) => { 4 | console.log(req.url, req.method, req.headers); 5 | 6 | if (req.url === '/') { 7 | res.setHeader('Content-Type', 'text/html'); 8 | res.write(''); 9 | res.write('Complete Coding'); 10 | res.write('

Welcome to Home

'); 11 | res.write(''); 12 | return res.end(); 13 | } else if (req.url === '/products') { 14 | res.setHeader('Content-Type', 'text/html'); 15 | res.write(''); 16 | res.write('Complete Coding'); 17 | res.write('

Checkout our products

'); 18 | res.write(''); 19 | return res.end(); 20 | } 21 | res.setHeader('Content-Type', 'text/html'); 22 | res.write(''); 23 | res.write('Complete Coding'); 24 | res.write('

Like / Share / Subscribe

'); 25 | res.write(''); 26 | res.end(); 27 | }); 28 | 29 | const PORT = 3001; 30 | server.listen(PORT, () => { 31 | console.log(`Server running on address http://localhost:${PORT}`); 32 | }); -------------------------------------------------------------------------------- /Chapter 4 - Request and Reponse/practise.js: -------------------------------------------------------------------------------- 1 | const http = require('http'); 2 | 3 | const server = http.createServer((req, res) => { 4 | console.log(req.url, req.method); 5 | if (req.url === '/home') { 6 | res.write('

Welcome to Home

'); 7 | return res.end(); 8 | } else if (req.url === '/men') { 9 | res.write('

Welcome to Men

'); 10 | return res.end(); 11 | } else if (req.url === '/women') { 12 | res.write('

Welcome to Women

'); 13 | return res.end(); 14 | } else if (req.url === '/kids') { 15 | res.write('

Welcome to Kids

'); 16 | return res.end(); 17 | } else if (req.url === '/cart') { 18 | res.write('

Welcome to Cart

'); 19 | return res.end(); 20 | } 21 | 22 | 23 | res.write(` 24 | 25 | 26 | Myntra 27 | 28 | 29 | 30 | 39 | 40 | 41 | 42 | `); 43 | res.end(); 44 | }); 45 | 46 | server.listen(3001, () => { 47 | console.log('Server running on address http://localhost:3001'); 48 | }); -------------------------------------------------------------------------------- /Chapter 4 - Request and Reponse/user.js: -------------------------------------------------------------------------------- 1 | const http = require('http'); 2 | const fs = require('fs'); 3 | 4 | const server = http.createServer((req, res) => { 5 | console.log(req.url, req.method, req.headers); 6 | 7 | if (req.url === '/') { 8 | res.setHeader('Content-Type', 'text/html'); 9 | res.write(''); 10 | res.write('Complete Coding'); 11 | res.write('

Enter Your Details:

'); 12 | res.write('
'); 13 | res.write('
'); 14 | res.write('') 15 | res.write('') 16 | res.write('') 17 | res.write('') 18 | res.write('
'); 19 | res.write('
'); 20 | res.write(''); 21 | res.write(''); 22 | return res.end(); 23 | 24 | } else if (req.url.toLowerCase() === "/submit-details" && 25 | req.method == "POST") { 26 | fs.writeFileSync('user.txt', 'Prashant Jain'); 27 | res.statusCode = 302; 28 | res.setHeader('Location', '/'); 29 | } 30 | res.setHeader('Content-Type', 'text/html'); 31 | res.write(''); 32 | res.write('Complete Coding'); 33 | res.write('

Like / Share / Subscribe

'); 34 | res.write(''); 35 | res.end(); 36 | }); 37 | 38 | const PORT = 3001; 39 | server.listen(PORT, () => { 40 | console.log(`Server running on address http://localhost:${PORT}`); 41 | }); -------------------------------------------------------------------------------- /Chapter 4 - Request and Reponse/user.txt: -------------------------------------------------------------------------------- 1 | Prashant Jain -------------------------------------------------------------------------------- /Chapter 5 - Parsing Request/app.js: -------------------------------------------------------------------------------- 1 | const http = require('http'); 2 | const requestHandler = require('./user'); 3 | 4 | const server = http.createServer(requestHandler); 5 | 6 | const PORT = 3001; 7 | server.listen(PORT, () => { 8 | console.log(`Server running on address http://localhost:${PORT}`); 9 | }); -------------------------------------------------------------------------------- /Chapter 5 - Parsing Request/calculator/app.js: -------------------------------------------------------------------------------- 1 | const http = require('http'); 2 | const { requestHandler } = require('./handler'); 3 | 4 | const server = http.createServer(requestHandler); 5 | 6 | const PORT = 3000; 7 | server.listen(PORT, () => { 8 | console.log(`Server running on address http://localhost:${PORT}`); 9 | }) -------------------------------------------------------------------------------- /Chapter 5 - Parsing Request/calculator/handler.js: -------------------------------------------------------------------------------- 1 | const {sumRequestHandler} = require('./sum'); 2 | 3 | const requestHandler = (req, res) => { 4 | console.log(req.url, req.method); 5 | if (req.url === '/') { 6 | res.setHeader('Content-Type', 'text/html'); 7 | res.write(` 8 | 9 | Practise Set 10 | 11 |

Welcome to Calculator

12 | Go To Calculator 13 | 14 | 15 | `); 16 | return res.end(); 17 | 18 | } else if (req.url.toLowerCase() === "/calculator") { 19 | res.setHeader('Content-Type', 'text/html'); 20 | res.write(` 21 | 22 | Practise Set 23 | 24 |

Here is the Calculator

25 |
26 | 27 | 28 | 29 |
30 | 31 | 32 | `); 33 | return res.end(); 34 | 35 | } else if (req.url.toLowerCase() === "/calculate-result" && 36 | req.method === 'POST') { 37 | return sumRequestHandler(req, res); 38 | } 39 | 40 | res.setHeader('Content-Type', 'text/html'); 41 | res.write(` 42 | 43 | Practise Set 44 | 45 |

404 Page Does not Exist

46 | Go To Home 47 | 48 | 49 | `); 50 | return res.end(); 51 | } 52 | 53 | exports.requestHandler = requestHandler; -------------------------------------------------------------------------------- /Chapter 5 - Parsing Request/calculator/sum.js: -------------------------------------------------------------------------------- 1 | const sumRequestHandler = (req, res) => { 2 | console.log("In Sum Request Handler", req.url); 3 | const body = []; 4 | req.on('data', chunk => body.push(chunk)); 5 | req.on('end', () => { 6 | const bodyStr = Buffer.concat(body).toString(); 7 | const params = new URLSearchParams(bodyStr); 8 | const bodyObj = Object.fromEntries(params); 9 | const result = Number(bodyObj.first) + Number(bodyObj.second); 10 | console.log(result); 11 | res.setHeader('Content-Type', 'text/html'); 12 | res.write(` 13 | 14 | Practise Set 15 | 16 |

Your Sum is ${result}

17 | 18 | 19 | `); 20 | return res.end(); 21 | }); 22 | } 23 | 24 | exports.sumRequestHandler = sumRequestHandler; -------------------------------------------------------------------------------- /Chapter 5 - Parsing Request/user.txt: -------------------------------------------------------------------------------- 1 | {"username":"Meera Jain","gender":"female"} -------------------------------------------------------------------------------- /Chapter 6 - Event Loop/calculator/app.js: -------------------------------------------------------------------------------- 1 | const http = require('http'); 2 | const { requestHandler } = require('./handler'); 3 | 4 | const server = http.createServer(requestHandler); 5 | 6 | const PORT = 3000; 7 | server.listen(PORT, () => { 8 | console.log(`Server running on address http://localhost:${PORT}`); 9 | }) -------------------------------------------------------------------------------- /Chapter 6 - Event Loop/calculator/handler.js: -------------------------------------------------------------------------------- 1 | const {sumRequestHandler} = require('./sum'); 2 | 3 | const requestHandler = (req, res) => { 4 | console.log(req.url, req.method); 5 | if (req.url === '/') { 6 | res.setHeader('Content-Type', 'text/html'); 7 | res.write(` 8 | 9 | Practise Set 10 | 11 |

Welcome to Calculator

12 | Go To Calculator 13 | 14 | 15 | `); 16 | return res.end(); 17 | 18 | } else if (req.url.toLowerCase() === "/calculator") { 19 | res.setHeader('Content-Type', 'text/html'); 20 | res.write(` 21 | 22 | Practise Set 23 | 24 |

Here is the Calculator

25 |
26 | 27 | 28 | 29 |
30 | 31 | 32 | `); 33 | return res.end(); 34 | 35 | } else if (req.url.toLowerCase() === "/calculate-result" && 36 | req.method === 'POST') { 37 | return sumRequestHandler(req, res); 38 | } 39 | 40 | res.setHeader('Content-Type', 'text/html'); 41 | res.write(` 42 | 43 | Practise Set 44 | 45 |

404 Page Does not Exist

46 | Go To Home 47 | 48 | 49 | `); 50 | return res.end(); 51 | } 52 | 53 | exports.requestHandler = requestHandler; -------------------------------------------------------------------------------- /Chapter 6 - Event Loop/calculator/sum.js: -------------------------------------------------------------------------------- 1 | const sumRequestHandler = (req, res) => { 2 | console.log("1. In Sum Request Handler", req.url); 3 | const body = []; 4 | let result; 5 | req.on('end', () => { 6 | console.log("3. End event came"); 7 | const bodyStr = Buffer.concat(body).toString(); 8 | const params = new URLSearchParams(bodyStr); 9 | const bodyObj = Object.fromEntries(params); 10 | result = Number(bodyObj.first) + Number(bodyObj.second); 11 | console.log(result); 12 | }); 13 | req.on('data', chunk => { 14 | body.push(chunk); 15 | console.log("2. Chunk Came"); 16 | }); 17 | 18 | console.log("4. Sending the response"); 19 | res.setHeader('Content-Type', 'text/html'); 20 | res.write(` 21 | 22 | Practise Set 23 | 24 |

Your Sum is ${result}

25 | 26 | 27 | `); 28 | return res.end(); 29 | } 30 | 31 | exports.sumRequestHandler = sumRequestHandler; -------------------------------------------------------------------------------- /Chapter 6 - Event Loop/user/app.js: -------------------------------------------------------------------------------- 1 | const http = require('http'); 2 | const requestHandler = require('./user'); 3 | 4 | const server = http.createServer(requestHandler); 5 | 6 | const PORT = 3001; 7 | server.listen(PORT, () => { 8 | console.log(`Server running on address http://localhost:${PORT}`); 9 | }); -------------------------------------------------------------------------------- /Chapter 6 - Event Loop/user/user.txt: -------------------------------------------------------------------------------- 1 | {"username":"Meera Jain","gender":"male"} -------------------------------------------------------------------------------- /Chapter 7 - npm and Tools/app.js: -------------------------------------------------------------------------------- 1 | const http = require('http'); 2 | 3 | const server = http.createServer((req, res) => { 4 | console.log(req); 5 | }); 6 | 7 | const PORT = 3002; 8 | server.listen(PORT, () => { 9 | console.log(`Server running on address http://localhost:${PORT}`); 10 | }); -------------------------------------------------------------------------------- /Chapter 7 - npm and Tools/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "npm-test", 3 | "version": "1.0.0", 4 | "description": "This project is being created to learn about npm.", 5 | "main": "app.js", 6 | "scripts": { 7 | "test": "echo \"Error: no test specified\" && exit 1", 8 | "start": "nodemon app.js", 9 | "khul-ja-sim-sim": "node app.js" 10 | }, 11 | "author": "Complete Coding", 12 | "license": "ISC", 13 | "devDependencies": { 14 | "nodemon": "^3.1.7" 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /Chapter 8 - Errors and Debugging/app.js: -------------------------------------------------------------------------------- 1 | const http = require('http'); 2 | const testingSyntax = require('./syntax') 3 | const runtime = require('./runtime') 4 | const logical = require('./logical') 5 | 6 | 7 | const requestHandler = require('./user'); 8 | 9 | const server = http.createServer(requestHandler); 10 | 11 | // const server = http.createServer((req, res) => { 12 | // console.log(req.url, req.method); 13 | // //testingSyntax(); 14 | // // runtime(); 15 | // logical(); 16 | // }); 17 | 18 | const PORT = 3002; 19 | server.listen(PORT, () => { 20 | console.log(`Server running on address http://localhost:${PORT}`); 21 | }); -------------------------------------------------------------------------------- /Chapter 8 - Errors and Debugging/logical.js: -------------------------------------------------------------------------------- 1 | const logical = () => { 2 | let num = 5; 3 | if (num = 10) { 4 | console.log(num); 5 | } else { 6 | console.log("num is not 10"); 7 | } 8 | 9 | 10 | 11 | }; 12 | 13 | module.exports = logical; -------------------------------------------------------------------------------- /Chapter 8 - Errors and Debugging/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "errors-and-debugging", 3 | "version": "1.0.0", 4 | "main": "app,js", 5 | "scripts": { 6 | "test": "echo \"Error: no test specified\" && exit 1", 7 | "start": "nodemon app.js" 8 | }, 9 | "author": "", 10 | "license": "ISC", 11 | "description": "", 12 | "dependencies": { 13 | "nodemon": "^3.1.7" 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /Chapter 8 - Errors and Debugging/runtime.js: -------------------------------------------------------------------------------- 1 | const runtime = () => { 2 | // console.log(x); 3 | let num = 98; 4 | num(); 5 | }; 6 | 7 | module.exports = runtime; -------------------------------------------------------------------------------- /Chapter 8 - Errors and Debugging/syntax.js: -------------------------------------------------------------------------------- 1 | const testingSyntax = () => { 2 | console.log("I am inside testing syntax") 3 | }; 4 | 5 | module.exports = testingSyntax; -------------------------------------------------------------------------------- /Chapter 9 - Introduction to Express/app.js: -------------------------------------------------------------------------------- 1 | // External Module 2 | const express = require('express'); 3 | 4 | const app = express(); 5 | 6 | app.get("/", (req, res, next) => { 7 | console.log("Came in first middleware", req.url, req.method); 8 | //res.send("

Came from First Middleware

"); 9 | next(); 10 | }); 11 | 12 | app.post("/submit-details", (req, res, next) => { 13 | console.log("Came in second middleware", req.url, req.method); 14 | res.send("

Welcome to Complete Coding Nodejs series

"); 15 | }); 16 | 17 | app.use("/", (req, res, next) => { 18 | console.log("Came in another middleware", req.url, req.method); 19 | res.send("

Came from another Middleware

"); 20 | }); 21 | 22 | 23 | const PORT = 3002; 24 | app.listen(PORT, () => { 25 | console.log(`Server running on address http://localhost:${PORT}`); 26 | }); -------------------------------------------------------------------------------- /Chapter 9 - Introduction to Express/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "errors-and-debugging", 3 | "version": "1.0.0", 4 | "main": "app,js", 5 | "scripts": { 6 | "test": "echo \"Error: no test specified\" && exit 1", 7 | "start": "nodemon app.js" 8 | }, 9 | "author": "", 10 | "license": "ISC", 11 | "description": "", 12 | "dependencies": { 13 | "express": "^4.21.0", 14 | "nodemon": "^3.1.7" 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /Complete NodeJS Notes.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Complete-Coding/NodeJS_Complete_YouTube/8db9b052a0403ad9796cc8a66329a72a55b4f5c8/Complete NodeJS Notes.pdf -------------------------------------------------------------------------------- /Practise Set/Chapter 10 - Contact Us/app.js: -------------------------------------------------------------------------------- 1 | // Core Module 2 | const path = require('path'); 3 | // External Module 4 | const express = require('express'); 5 | // Local Module 6 | const rootDir = require('./utils/pathUtil'); 7 | const homeRouter = require('./routes/homeRouter'); 8 | const contactRouter = require('./routes/contactRouter'); 9 | 10 | const app = express(); 11 | 12 | app.use(express.urlencoded()); 13 | 14 | app.use(homeRouter); 15 | app.use(contactRouter); 16 | 17 | app.use((req, res, next) => { 18 | res.sendFile(path.join(rootDir, "views", "404.html")); 19 | }) 20 | 21 | const PORT = 3000; 22 | app.listen(PORT, () => { 23 | console.log(`Server running on address http://localhost:${PORT}`); 24 | }); -------------------------------------------------------------------------------- /Practise Set/Chapter 10 - Contact Us/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "chapter-9---contact-us", 3 | "version": "1.0.0", 4 | "main": "index.js", 5 | "scripts": { 6 | "test": "echo \"Error: no test specified\" && exit 1", 7 | "start": "nodemon app.js" 8 | }, 9 | "keywords": [], 10 | "author": "", 11 | "license": "ISC", 12 | "description": "", 13 | "devDependencies": { 14 | "nodemon": "^3.1.7" 15 | }, 16 | "dependencies": { 17 | "express": "^4.21.0" 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /Practise Set/Chapter 10 - Contact Us/routes/contactRouter.js: -------------------------------------------------------------------------------- 1 | // Core Module 2 | const path = require('path'); 3 | // External Module 4 | const express = require('express'); 5 | // Local Module 6 | const rootDir = require('../utils/pathUtil'); 7 | 8 | const contactRouter = express.Router(); 9 | 10 | contactRouter.get("/contact-us", (req, res, next) => { 11 | res.sendFile(path.join(rootDir, "views", "contact-us.html")); 12 | }); 13 | 14 | contactRouter.post("/contact-us", (req, res, next) => { 15 | console.log("hello from us"); 16 | console.log(req.body); 17 | res.sendFile(path.join(rootDir, "views", "contact-success.html")); 18 | }) 19 | 20 | module.exports = contactRouter; -------------------------------------------------------------------------------- /Practise Set/Chapter 10 - Contact Us/routes/homeRouter.js: -------------------------------------------------------------------------------- 1 | // Core Module 2 | const path = require('path'); 3 | // External Module 4 | const express = require('express'); 5 | // Local Module 6 | const rootDir = require('../utils/pathUtil'); 7 | 8 | const homeRouter = express.Router(); 9 | 10 | homeRouter.get("/", (req, res, next) => { 11 | console.log("Handling / for GET", req.url, req.method); 12 | res.sendFile(path.join(rootDir, "views", "home.html")); 13 | }) 14 | 15 | module.exports = homeRouter; -------------------------------------------------------------------------------- /Practise Set/Chapter 10 - Contact Us/utils/pathUtil.js: -------------------------------------------------------------------------------- 1 | // Core Module 2 | const path = require('path'); 3 | 4 | module.exports = path.dirname(require.main.filename); -------------------------------------------------------------------------------- /Practise Set/Chapter 10 - Contact Us/views/404.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | Page Not Found 7 | 8 | 9 |
10 |

Error: Your page is not found here.

11 |
12 | 13 | -------------------------------------------------------------------------------- /Practise Set/Chapter 10 - Contact Us/views/contact-success.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | Thanks for Contacting 7 | 8 | 9 |
10 |

We will contact you shortly

11 |
12 | 13 | -------------------------------------------------------------------------------- /Practise Set/Chapter 10 - Contact Us/views/contact-us.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | Contact Us 7 | 8 | 9 |
10 |

Please give your details here

11 |
12 |
13 | 14 | 15 | 16 |
17 |
18 | 19 | -------------------------------------------------------------------------------- /Practise Set/Chapter 10 - Contact Us/views/home.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | Complete Coding Home 7 | 8 | 9 |
10 |

Welcome to Complete Coding

11 |
12 | 13 | -------------------------------------------------------------------------------- /Practise Set/Chapter 12 - Dynamic/app.js: -------------------------------------------------------------------------------- 1 | // Core Module 2 | const path = require('path'); 3 | 4 | // External Module 5 | const express = require('express'); 6 | 7 | //Local Module 8 | const userRouter = require("./routes/userRouter") 9 | const {hostRouter} = require("./routes/hostRouter") 10 | const rootDir = require("./utils/pathUtil"); 11 | 12 | const app = express(); 13 | 14 | app.set('view engine', 'ejs'); 15 | app.set('views', 'views'); 16 | 17 | app.use(express.urlencoded()); 18 | app.use(userRouter); 19 | app.use("/host", hostRouter); 20 | 21 | app.use(express.static(path.join(rootDir, 'public'))) 22 | 23 | app.use((req, res, next) => { 24 | res.status(404).render('404', {pageTitle: 'Page Not Found', currentPage: '404'}); 25 | }) 26 | 27 | const PORT = 3000; 28 | app.listen(PORT, () => { 29 | console.log(`Server running on address http://localhost:${PORT}`); 30 | }); -------------------------------------------------------------------------------- /Practise Set/Chapter 12 - Dynamic/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "chapter-10---airbnb", 3 | "version": "1.0.0", 4 | "main": "index.js", 5 | "scripts": { 6 | "test": "echo \"Error: no test specified\" && exit 1", 7 | "tailwind": "tailwindcss -i ./views/input.css -o ./public/output.css --watch", 8 | "start": "nodemon app.js & npm run tailwind" 9 | }, 10 | "keywords": [], 11 | "author": "", 12 | "license": "ISC", 13 | "description": "", 14 | "devDependencies": { 15 | "autoprefixer": "^10.4.20", 16 | "nodemon": "^3.1.7", 17 | "postcss": "^8.4.47", 18 | "tailwindcss": "^3.4.13" 19 | }, 20 | "dependencies": { 21 | "body-parser": "^1.20.3", 22 | "ejs": "^3.1.10", 23 | "express": "^4.21.0" 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /Practise Set/Chapter 12 - Dynamic/public/home.css: -------------------------------------------------------------------------------- 1 | body { 2 | font-family: 'Arial', sans-serif; 3 | margin: 0; 4 | padding: 0; 5 | background-color: #f5f5f5; 6 | } 7 | 8 | header { 9 | background-color: #ff5a5f; 10 | padding: 1rem 2rem; 11 | box-shadow: 0px 2px 8px rgba(0, 0, 0, 0.1); 12 | } 13 | 14 | nav { 15 | display: flex; 16 | justify-content: space-between; 17 | align-items: center; 18 | } 19 | 20 | nav ul { 21 | list-style: none; 22 | margin: 0; 23 | padding: 0; 24 | display: flex; 25 | } 26 | 27 | nav li { 28 | margin-left: 20px; 29 | } 30 | 31 | nav a { 32 | text-decoration: none; 33 | color: white; 34 | font-weight: bold; 35 | padding: 0.5rem 1rem; 36 | border-radius: 4px; 37 | transition: background-color 0.3s ease; 38 | } 39 | 40 | nav a:hover { 41 | background-color: #e54e52; 42 | } 43 | 44 | main { 45 | text-align: center; 46 | padding: 5rem 2rem; 47 | background-color: #fff; 48 | box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1); 49 | margin: 2rem auto; 50 | max-width: 600px; 51 | border-radius: 8px; 52 | } 53 | 54 | h2 { 55 | color: #333; 56 | font-size: 2rem; 57 | } -------------------------------------------------------------------------------- /Practise Set/Chapter 12 - Dynamic/routes/hostRouter.js: -------------------------------------------------------------------------------- 1 | // Core Module 2 | const path = require('path'); 3 | 4 | // External Module 5 | const express = require('express'); 6 | const hostRouter = express.Router(); 7 | 8 | // Local Module 9 | const rootDir = require("../utils/pathUtil"); 10 | 11 | hostRouter.get("/add-home", (req, res, next) => { 12 | res.render('addHome', {pageTitle: 'Add Home to airbnb', currentPage: 'addHome'}); 13 | }) 14 | 15 | const registeredHomes = []; 16 | 17 | hostRouter.post("/add-home", (req, res, next) => { 18 | console.log('Home Registration successful for:', req.body); 19 | registeredHomes.push(req.body); 20 | res.render('homeAdded', {pageTitle: 'Home Added Successfully', currentPage: 'homeAdded'}); 21 | }) 22 | 23 | exports.hostRouter = hostRouter; 24 | exports.registeredHomes = registeredHomes; 25 | -------------------------------------------------------------------------------- /Practise Set/Chapter 12 - Dynamic/routes/userRouter.js: -------------------------------------------------------------------------------- 1 | // Core Modules 2 | const path = require('path'); 3 | 4 | // External Module 5 | const express = require('express'); 6 | const userRouter = express.Router(); 7 | 8 | // Local Module 9 | const { registeredHomes } = require('./hostRouter'); 10 | 11 | userRouter.get("/", (req, res, next) => { 12 | console.log(registeredHomes); 13 | res.render('home', {registeredHomes: registeredHomes, pageTitle: 'airbnb Home', currentPage: 'Home'}); 14 | }); 15 | 16 | module.exports = userRouter; -------------------------------------------------------------------------------- /Practise Set/Chapter 12 - Dynamic/tailwind.config.js: -------------------------------------------------------------------------------- 1 | /** @type {import('tailwindcss').Config} */ 2 | module.exports = { 3 | content: ["./views/**/*.{html,ejs}"], 4 | theme: { 5 | extend: {}, 6 | }, 7 | plugins: [], 8 | } 9 | 10 | -------------------------------------------------------------------------------- /Practise Set/Chapter 12 - Dynamic/utils/pathUtil.js: -------------------------------------------------------------------------------- 1 | // Core Module 2 | const path = require('path'); 3 | 4 | module.exports = path.dirname(require.main.filename); -------------------------------------------------------------------------------- /Practise Set/Chapter 12 - Dynamic/views/404.ejs: -------------------------------------------------------------------------------- 1 | <%- include('partials/head') %> 2 | 3 | 4 | <%- include('partials/nav') %> 5 |
6 |

404

7 |

Oops! Page Not Found

8 | Go Back Home 13 |
14 | 15 | 16 | -------------------------------------------------------------------------------- /Practise Set/Chapter 12 - Dynamic/views/addHome.ejs: -------------------------------------------------------------------------------- 1 | <%- include('partials/head') %> 2 | 3 | 4 | <%- include('partials/nav') %> 5 |
6 |

Register Your Home on AirBnB

7 |
8 | 13 | 18 | 23 | 28 | 33 | 34 |
35 |
36 | 37 | 38 | -------------------------------------------------------------------------------- /Practise Set/Chapter 12 - Dynamic/views/homeAdded.ejs: -------------------------------------------------------------------------------- 1 | <%- include('partials/head') %> 2 | 3 | 4 | <%- include('partials/nav') %> 5 |
6 |
7 |

Home Registered Successfully

8 |

Your home has been added to our listings.

9 | Return to Home 10 |
11 |
12 | 13 | 14 | -------------------------------------------------------------------------------- /Practise Set/Chapter 12 - Dynamic/views/input.css: -------------------------------------------------------------------------------- 1 | @tailwind base; 2 | @tailwind components; 3 | @tailwind utilities; -------------------------------------------------------------------------------- /Practise Set/Chapter 12 - Dynamic/views/partials/head.ejs: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | <%= pageTitle %> 7 | -------------------------------------------------------------------------------- /Practise Set/Chapter 12 - Dynamic/views/partials/nav.ejs: -------------------------------------------------------------------------------- 1 |
2 | 20 |
-------------------------------------------------------------------------------- /Practise Set/Chapter 9 - Contact Us/app.js: -------------------------------------------------------------------------------- 1 | // External Module 2 | const express = require('express'); 3 | 4 | const app = express(); 5 | 6 | app.use((req, res, next) => { 7 | console.log("First Dummy Middleware", req.url, req.method); 8 | next(); 9 | }); 10 | 11 | app.use((req, res, next) => { 12 | console.log("Second Dummy Middleware", req.url, req.method); 13 | next(); 14 | }); 15 | 16 | // app.use((req, res, next) => { 17 | // console.log("Third Middleware", req.url, req.method); 18 | // res.send("

Welcome to Complete Coding

"); 19 | // }); 20 | 21 | app.get("/", (req, res, next) => { 22 | console.log("Handling / for GET", req.url, req.method); 23 | res.send(`

Welcome to Complete Coding

`); 24 | }) 25 | 26 | app.get("/contact-us", (req, res, next) => { 27 | console.log("Handling /contact-us for GET", req.url, req.method); 28 | res.send( 29 | `

Please give your details here

30 |
31 | 32 | 33 | 34 |
35 | `); 36 | }); 37 | 38 | app.post("/contact-us", (req, res, next) => { 39 | console.log("Handling /contact-us for POST", req.url, req.method); 40 | res.send(`

We will contact you shortly

`); 41 | }) 42 | 43 | const PORT = 3000; 44 | app.listen(PORT, () => { 45 | console.log(`Server running on address http://localhost:${PORT}`); 46 | }); -------------------------------------------------------------------------------- /Practise Set/Chapter 9 - Contact Us/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "chapter-9---contact-us", 3 | "version": "1.0.0", 4 | "main": "index.js", 5 | "scripts": { 6 | "test": "echo \"Error: no test specified\" && exit 1", 7 | "start": "nodemon app.js" 8 | }, 9 | "keywords": [], 10 | "author": "", 11 | "license": "ISC", 12 | "description": "", 13 | "devDependencies": { 14 | "nodemon": "^3.1.7" 15 | }, 16 | "dependencies": { 17 | "express": "^4.21.0" 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # [ 🎬 Complete NodeJS Playlist](https://www.youtube.com/playlist?list=PL78RhpUUKSwfeSOOwfE9x6l5jTjn5LbY3) 2 | 3 | ![1](https://github.com/KG-Coding-with-Prashant-Sir/NodeJS_Complete_YouTube/assets/102736197/4f510694-1830-43ad-bc37-cb47d5dea5fa) 4 | --------------------------------------------------------------------------------