├── Express Class 01 ├── .gitignore ├── README.md ├── data.json ├── index.html ├── index.js ├── package-lock.json ├── package.json ├── previous.js └── public │ ├── data.json │ ├── demo.html │ └── error.html ├── Grand Hackathon ├── .gitignore ├── client │ ├── .gitignore │ ├── README.md │ ├── package-lock.json │ ├── package.json │ ├── public │ │ ├── ask.png │ │ ├── favicon.ico │ │ ├── index.html │ │ ├── logo192.png │ │ ├── logo512.png │ │ ├── manifest.json │ │ └── robots.txt │ └── src │ │ ├── App.css │ │ ├── App.js │ │ ├── App.test.js │ │ ├── assets │ │ ├── banner-image.jpg │ │ ├── docter.jpg │ │ ├── icon02-free-img.png │ │ ├── icon03-free-img.png │ │ ├── icon04-free-img.png │ │ ├── icon05-free-img.png │ │ ├── icon06-free-img.png │ │ └── logo.png │ │ ├── components │ │ ├── center.jsx │ │ └── navbar.jsx │ │ ├── index.css │ │ ├── index.js │ │ ├── pages │ │ ├── About.jsx │ │ ├── Allapointment.jsx │ │ ├── Appointment.jsx │ │ ├── Doctor.jsx │ │ ├── Error.jsx │ │ ├── Home.jsx │ │ ├── OurDoctors.jsx │ │ └── Pateints.jsx │ │ ├── reportWebVitals.js │ │ ├── routing │ │ └── routing.jsx │ │ ├── setupTests.js │ │ ├── styles │ │ ├── Center.css │ │ └── appoi.css │ │ └── todoapp.jsx └── server │ ├── .gitignore │ ├── index.js │ ├── models │ ├── appointment.js │ └── doctor.js │ ├── package-lock.json │ ├── package.json │ └── routes │ ├── aproutes.js │ ├── drroutes.js │ └── routes.js ├── MVC ├── .gitignore ├── README.md ├── controller │ └── product.js ├── data.json ├── index.js ├── package-lock.json ├── package.json └── routes │ └── routes.js ├── MongoDb-Commands ├── No SQL.png ├── README.md └── mongodbAtlas_mongodbCompass_postman.jpg ├── MongoDb ├── .gitignore ├── README.md ├── controller │ └── product.js ├── data.json ├── index.js ├── package-lock.json ├── package.json └── routes │ └── routes.js ├── Mongoose ├── .gitignore ├── README.md ├── index.js ├── models │ └── usermodel.js ├── package-lock.json ├── package.json └── routes │ └── userrouter.js ├── Node Class 01 ├── .gitignore ├── README.md ├── index.js ├── intro.txt ├── package-lock.json ├── package.json └── this.js ├── Node Class 02 ├── README.md ├── data.json ├── error.html ├── index.html ├── index.js └── package.json ├── Node.JS └── Get started instructions.txt ├── README.md ├── REST-API ├── .gitignore ├── README.md ├── RESTAPI.png ├── data.json ├── index.js ├── package-lock.json └── package.json ├── Softwares.txt ├── Status Code └── Status Code.pdf └── repo.png /Express Class 01/.gitignore: -------------------------------------------------------------------------------- 1 | node_modules -------------------------------------------------------------------------------- /Express Class 01/README.md: -------------------------------------------------------------------------------- 1 | ## Chapter 3 - Express JS 2 | 3 | ### [[ Chapter Notes ]] 4 | 5 | - **ExpressJS** is *de-facto* Node framework - and used in most Node applications which are used as web server. 6 | - You can install express `npm install express` 7 | - Express has few level of methods : 8 | - Application methods : e.g. app.use() 9 | - Request methods 10 | - Response methods 11 | - Middleware methods 12 | - Router methods 13 | 14 | - **Response** methods (**res** is our response objects) 15 | - **res.send()** - for sending HTML 16 | - **res.sendFile(**) - for sending File 17 | - **res.json** - for sending JSON 18 | - **res.sendStatus(404)** - for sending HTTP status only 19 | 20 | - **HTTP Request** Types we generally use : 21 | - GET 22 | - POST 23 | - PUT 24 | - DELETE 25 | - PATCH 26 | - API / Endpoints / Routes are used inter-changeably but they are related to server paths. 27 | 28 | - **Middle-ware** : Modifies the request before it reaches the next middleware or endpoints. 29 | - Sequence of middleware is very important, as first middleware is first traversed by request. 30 | - Middle-wares can be used for many use cases, like loggers, authentication, parsing data etc. 31 | - Middle-ware can be : 32 | - Application level : server.use(**middleware**) 33 | - Router level : server.get('/', **middleware**, (req,res)=>{}) 34 | - Built-in middleware : **express.json()** [ for parsing body data], **express.static()**[for static hosting] 35 | - External Middle-wares - like **morgan** 36 | 37 | - **Request** properties (**req** is our request object) 38 | - **req.ip** - IP address of client 39 | - **req.method** - HTTP method of request 40 | - **req.hostname** - like google.com / localhost 41 | - **req.query** - for capturing query parameters from URL e.g. localhost:8080 ? **query=value** 42 | - **req.body** -for capturing request body data (but its needs a middleware for body data decoding) 43 | - **req.params** - for capturing URL parameters for route path like `/products/:id` 44 | 45 | - **Static Hosting** : we can make 1 or more folders as static hosted using **express.static** middleware. 46 | `server.use(express.static(< directory >))` 47 | Static hosting is like sharing a folder/directory and making its file readable as it is. 48 | Note : `index.html` is default file which would be read in a static hosted folder, if you don't mention any file name. 49 | 50 | 3 major ways of sending data from client to server via request are : 51 | 52 | **1. Send data via URL in Query String** 53 | 54 | This is easiest method to send data and mostly used in GET request. 55 | 56 | When you have URL with `?name=Youstart&subject=express` at end, it translates in a query string. In query string each key,value pair is separated by `=` and between 2 such pairs we put `&`. 57 | 58 | To read such data in express you can use `req.query` : 59 | ```javascript 60 | server.get("/demo",function(req,res){ 61 | console.log(req.query) // prints all data in request object 62 | res.send(req.query); // send back same data in response object 63 | }) 64 | ``` 65 | 66 | - **Assignment 1** : 67 | 68 | Make above server with API endpoint `/demo` as shown above : 69 | 70 | 1. Try to call this API in your browser `http://localhost:8080/demo?name=Youstart` - this will return a response of `req.query` JSON object 71 | 72 | 2. Create 3 query parameters `name`, `age`, `subject` with some values. Check the final output of `req.query` - can you find all data on server side. Can you send it back to client via `res` object. 73 | 74 | 75 | **2. Send data via Request Params** 76 | 77 | In this method you can have a URL with url path like `/Youstart/express` at end it translates in a param string. In param part string each value is separated by `/`. As you can see that URL only contains `value` not the `key` part of data. `key` part is decided by the endpoint definition at express server 78 | 79 | server.get("/demo/:name/:subject",function(req,res){ 80 | console.log(req.params) // prints all data in request object 81 | res.send(req.query); // send back same data in response object 82 | }) 83 | 84 | So sequence of values matter in this case. As values sent from client are matched with `name` and `subject` params of URL later. 85 | 86 | - **Assignment 2** : 87 | 88 | Make above server with API endpoint `/demo` as shown above : 89 | 90 | 1. Try to call this API in your browser `http://localhost:8080/demo/Youstart/Express` - this will return a response of `req.params` JSON object 91 | 92 | 2. Create 3 URL params `name`, `age`, `subject` . Call the URL and check the final output of `req.params` - can you find all data on server side. Can you send it back to client via `res` object. 93 | 94 | 95 | **3. Send data via Request Body** 96 | 97 | Final method of sending data is via body part of request. We can send data directly to body using URL. We have to either use one of these methods 98 | 99 | 1. Use a HTML Form and make `method` value as `POST`. This will make all name=value pair to go via body of request. 100 | 101 | 2. Use special browsers like POSTMAN to change the body directly. (We will see this example in next classes) 102 | 103 | ```js 104 | server.post("/demo",function(req,res){ 105 | console.log(req.body) // prints all data in request object 106 | res.send(req.body); // send back same data in response object 107 | }) -------------------------------------------------------------------------------- /Express Class 01/index.html: -------------------------------------------------------------------------------- 1 | 5 | 9 | 210 | 211 |
212 |
213 |
214 |
215 |
216 |
217 |
218 | -25% 219 | 220 |
221 |
222 | 223 | 227 |
228 | 229 |
230 |
231 |
***title***
232 | 233 |
234 | ₹ ***price*** 235 | ₹ 700 236 |
237 |
238 | 239 | 240 | 241 |
242 |
243 | 244 | ***rating*** 245 |
246 | 247 | ***buy*** 248 |
249 |
250 |
251 | 252 | 253 |
254 | 255 |
256 |
-------------------------------------------------------------------------------- /Express Class 01/index.js: -------------------------------------------------------------------------------- 1 | const data = require('./data.json'); 2 | const express = require('express'); 3 | const server = express() 4 | 5 | // It is third party middlewear 6 | const morgan = require('morgan'); 7 | server.use(morgan('default')) 8 | 9 | 10 | // It is Built-In Middlewear 11 | server.use(express.json()); 12 | server.use(express.static("public")); 13 | 14 | 15 | 16 | // It is Application-Base Middlewear 17 | 18 | // server.use((req,res,next)=>{ 19 | // // console.log(req.hostname,req.ip,req.method); 20 | // console.log(req.get("Sec-Ch-Ua-Platform")); 21 | // next(); 22 | // }) 23 | 24 | 25 | // It is Routes-Based Middlwear 26 | 27 | const auth = (req,res,next)=>{ 28 | if (req.body.password == 'arham786') { 29 | console.log(req.body); 30 | next(); 31 | } else { 32 | res.sendStatus(401); 33 | console.error("Your Password is incorrect"); 34 | } 35 | } 36 | 37 | 38 | 39 | // API , End-Point , Routes 40 | server.get('/', (req, res) => { 41 | // res.json(data) 42 | res.send("This is my GET API") 43 | // res.status(203).send("

I sens status code 202

") 44 | // res.send(req.get("Status Code")) 45 | // res.sendFile('./index.html') 46 | // console.log(); 47 | console.log("GET API DONE"); 48 | }) 49 | server.patch('/',auth, (req, res) => { 50 | 51 | res.send("Server Started with Patch Api") 52 | console.log("Server Started with Patch Api"); 53 | }) 54 | server.post('/', (req, res) => { 55 | // res.send("Server Started with Post Api") 56 | res.json({type:"POST API"}) 57 | console.log("Server Started with Post Api"); 58 | }) 59 | server.delete('/', (req, res) => { 60 | res.send("Server Started with Delete Api") 61 | console.log("Server Started with Delete Api"); 62 | }) 63 | 64 | 65 | 66 | 67 | server.listen(8080, () => { 68 | console.log("Server Running on Port 8080"); 69 | }) -------------------------------------------------------------------------------- /Express Class 01/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "node-class-02", 3 | "version": "1.0.0", 4 | "description": "", 5 | "main": "index.js", 6 | "scripts": { 7 | "start": "nodemon index.js", 8 | "test": "echo \"Error: no test specified\" && exit 1" 9 | }, 10 | "keywords": [], 11 | "author": "", 12 | "license": "ISC", 13 | "dependencies": { 14 | "express": "^4.18.2", 15 | "morgan": "^1.10.0" 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /Express Class 01/previous.js: -------------------------------------------------------------------------------- 1 | const http = require('http') 2 | const fs = require('fs') 3 | const readfs = fs.readFileSync('./index.html', 'utf-8') 4 | const jsondata = JSON.parse(fs.readFileSync('./data.json', 'utf-8')); 5 | const error = fs.readFileSync('./error.html', 'utf-8') 6 | const product = jsondata.products; 7 | 8 | 9 | 10 | 11 | const server = http.createServer((req, res) => { 12 | if (req.url.startsWith('/product')) { 13 | const id = req.url.split('/')[2]; 14 | const newprd = product.find(p => p.id === (+id)); 15 | console.log(newprd); 16 | 17 | if (newprd) { 18 | res.setHeader("Content-Type", "text/html"); 19 | const modifydata = readfs 20 | .replace('***title***', newprd.title) 21 | .replace('***price***', newprd.price) 22 | .replace('***rating***', newprd.rating) 23 | .replace('***url***', newprd.thumbnail) 24 | .replace('***buy***', newprd.brand); 25 | res.end(modifydata); 26 | } else { 27 | } 28 | return; 29 | } 30 | 31 | switch (req.url) { 32 | case "/": 33 | res.setHeader("Content-Type", "text/html") 34 | res.end(readfs) 35 | break; 36 | case "/api": 37 | res.setHeader("Content-Type", "application/json") 38 | res.end(JSON.stringify(jsondata)); 39 | break; 40 | default: 41 | res.setHeader("Content-Type", "text/html") 42 | res.end(error) 43 | 44 | } 45 | console.log("Server Started") 46 | }) 47 | server.listen(8080); 48 | 49 | 50 | 51 | 52 | 53 | -------------------------------------------------------------------------------- /Express Class 01/public/demo.html: -------------------------------------------------------------------------------- 1 | 5 | 9 | 210 | 211 |
212 |
213 |
214 |
215 |
216 |
217 |
218 | -25% 219 | 220 |
221 |
222 | 223 | 227 |
228 | 229 |
230 |
231 |
***title***
232 | 233 |
234 | ₹ ***price*** 235 | ₹ 700 236 |
237 |
238 | 239 | 240 | 241 |
242 |
243 | 244 | ***rating*** 245 |
246 | 247 | ***buy*** 248 |
249 |
250 |
251 | 252 | 253 |
254 | 255 |
256 |
-------------------------------------------------------------------------------- /Express Class 01/public/error.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | Error Page 7 | 8 | 9 | 10 |

404 ERROR

11 |

Page Not Found

12 | 13 | -------------------------------------------------------------------------------- /Grand Hackathon/.gitignore: -------------------------------------------------------------------------------- 1 | node_modules 2 | .env -------------------------------------------------------------------------------- /Grand Hackathon/client/.gitignore: -------------------------------------------------------------------------------- 1 | node_modules 2 | .env -------------------------------------------------------------------------------- /Grand Hackathon/client/README.md: -------------------------------------------------------------------------------- 1 | # Getting Started with Create React App 2 | 3 | This project was bootstrapped with [Create React App](https://github.com/facebook/create-react-app). 4 | 5 | ## Available Scripts 6 | 7 | In the project directory, you can run: 8 | 9 | ### `npm start` 10 | 11 | Runs the app in the development mode.\ 12 | Open [http://localhost:3000](http://localhost:3000) to view it in your browser. 13 | 14 | The page will reload when you make changes.\ 15 | You may also see any lint errors in the console. 16 | 17 | ### `npm test` 18 | 19 | Launches the test runner in the interactive watch mode.\ 20 | See the section about [running tests](https://facebook.github.io/create-react-app/docs/running-tests) for more information. 21 | 22 | ### `npm run build` 23 | 24 | Builds the app for production to the `build` folder.\ 25 | It correctly bundles React in production mode and optimizes the build for the best performance. 26 | 27 | The build is minified and the filenames include the hashes.\ 28 | Your app is ready to be deployed! 29 | 30 | See the section about [deployment](https://facebook.github.io/create-react-app/docs/deployment) for more information. 31 | 32 | ### `npm run eject` 33 | 34 | **Note: this is a one-way operation. Once you `eject`, you can't go back!** 35 | 36 | If you aren't satisfied with the build tool and configuration choices, you can `eject` at any time. This command will remove the single build dependency from your project. 37 | 38 | Instead, it will copy all the configuration files and the transitive dependencies (webpack, Babel, ESLint, etc) right into your project so you have full control over them. All of the commands except `eject` will still work, but they will point to the copied scripts so you can tweak them. At this point you're on your own. 39 | 40 | You don't have to ever use `eject`. The curated feature set is suitable for small and middle deployments, and you shouldn't feel obligated to use this feature. However we understand that this tool wouldn't be useful if you couldn't customize it when you are ready for it. 41 | 42 | ## Learn More 43 | 44 | You can learn more in the [Create React App documentation](https://facebook.github.io/create-react-app/docs/getting-started). 45 | 46 | To learn React, check out the [React documentation](https://reactjs.org/). 47 | 48 | ### Code Splitting 49 | 50 | This section has moved here: [https://facebook.github.io/create-react-app/docs/code-splitting](https://facebook.github.io/create-react-app/docs/code-splitting) 51 | 52 | ### Analyzing the Bundle Size 53 | 54 | This section has moved here: [https://facebook.github.io/create-react-app/docs/analyzing-the-bundle-size](https://facebook.github.io/create-react-app/docs/analyzing-the-bundle-size) 55 | 56 | ### Making a Progressive Web App 57 | 58 | This section has moved here: [https://facebook.github.io/create-react-app/docs/making-a-progressive-web-app](https://facebook.github.io/create-react-app/docs/making-a-progressive-web-app) 59 | 60 | ### Advanced Configuration 61 | 62 | This section has moved here: [https://facebook.github.io/create-react-app/docs/advanced-configuration](https://facebook.github.io/create-react-app/docs/advanced-configuration) 63 | 64 | ### Deployment 65 | 66 | This section has moved here: [https://facebook.github.io/create-react-app/docs/deployment](https://facebook.github.io/create-react-app/docs/deployment) 67 | 68 | ### `npm run build` fails to minify 69 | 70 | This section has moved here: [https://facebook.github.io/create-react-app/docs/troubleshooting#npm-run-build-fails-to-minify](https://facebook.github.io/create-react-app/docs/troubleshooting#npm-run-build-fails-to-minify) 71 | -------------------------------------------------------------------------------- /Grand Hackathon/client/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "todo-app", 3 | "version": "0.1.0", 4 | "private": true, 5 | "dependencies": { 6 | "@testing-library/jest-dom": "^5.17.0", 7 | "@testing-library/react": "^13.4.0", 8 | "@testing-library/user-event": "^13.5.0", 9 | "axios": "^1.6.2", 10 | "react": "^18.2.0", 11 | "react-dom": "^18.2.0", 12 | "react-router-dom": "^6.20.1", 13 | "react-scripts": "5.0.1", 14 | "react-toastify": "^9.1.3", 15 | "web-vitals": "^2.1.4" 16 | }, 17 | "scripts": { 18 | "start": "react-scripts start", 19 | "build": "react-scripts build", 20 | "test": "react-scripts test", 21 | "eject": "react-scripts eject" 22 | }, 23 | "eslintConfig": { 24 | "extends": [ 25 | "react-app", 26 | "react-app/jest" 27 | ] 28 | }, 29 | "browserslist": { 30 | "production": [ 31 | ">0.2%", 32 | "not dead", 33 | "not op_mini all" 34 | ], 35 | "development": [ 36 | "last 1 chrome version", 37 | "last 1 firefox version", 38 | "last 1 safari version" 39 | ] 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /Grand Hackathon/client/public/ask.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/arhamansari11/Backend-Developement/f0765184454f09164178677f8fb0c52ef40c64b4/Grand Hackathon/client/public/ask.png -------------------------------------------------------------------------------- /Grand Hackathon/client/public/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/arhamansari11/Backend-Developement/f0765184454f09164178677f8fb0c52ef40c64b4/Grand Hackathon/client/public/favicon.ico -------------------------------------------------------------------------------- /Grand Hackathon/client/public/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 12 | 13 | 17 | 18 | 27 | 28 | Dr.Teeth 29 | 30 | 31 | 32 |
33 | 43 | 44 | 45 | 46 | -------------------------------------------------------------------------------- /Grand Hackathon/client/public/logo192.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/arhamansari11/Backend-Developement/f0765184454f09164178677f8fb0c52ef40c64b4/Grand Hackathon/client/public/logo192.png -------------------------------------------------------------------------------- /Grand Hackathon/client/public/logo512.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/arhamansari11/Backend-Developement/f0765184454f09164178677f8fb0c52ef40c64b4/Grand Hackathon/client/public/logo512.png -------------------------------------------------------------------------------- /Grand Hackathon/client/public/manifest.json: -------------------------------------------------------------------------------- 1 | { 2 | "short_name": "React App", 3 | "name": "Create React App Sample", 4 | "icons": [ 5 | { 6 | "src": "favicon.ico", 7 | "sizes": "64x64 32x32 24x24 16x16", 8 | "type": "image/x-icon" 9 | }, 10 | { 11 | "src": "logo192.png", 12 | "type": "image/png", 13 | "sizes": "192x192" 14 | }, 15 | { 16 | "src": "logo512.png", 17 | "type": "image/png", 18 | "sizes": "512x512" 19 | } 20 | ], 21 | "start_url": ".", 22 | "display": "standalone", 23 | "theme_color": "#000000", 24 | "background_color": "#ffffff" 25 | } 26 | -------------------------------------------------------------------------------- /Grand Hackathon/client/public/robots.txt: -------------------------------------------------------------------------------- 1 | # https://www.robotstxt.org/robotstxt.html 2 | User-agent: * 3 | Disallow: 4 | -------------------------------------------------------------------------------- /Grand Hackathon/client/src/App.css: -------------------------------------------------------------------------------- 1 | .App { 2 | text-align: center; 3 | } 4 | 5 | .App-logo { 6 | height: 40vmin; 7 | pointer-events: none; 8 | } 9 | 10 | @media (prefers-reduced-motion: no-preference) { 11 | .App-logo { 12 | animation: App-logo-spin infinite 20s linear; 13 | } 14 | } 15 | 16 | .App-header { 17 | background-color: #282c34; 18 | min-height: 100vh; 19 | display: flex; 20 | flex-direction: column; 21 | align-items: center; 22 | justify-content: center; 23 | font-size: calc(10px + 2vmin); 24 | color: white; 25 | } 26 | 27 | .App-link { 28 | color: #61dafb; 29 | } 30 | 31 | @keyframes App-logo-spin { 32 | from { 33 | transform: rotate(0deg); 34 | } 35 | to { 36 | transform: rotate(360deg); 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /Grand Hackathon/client/src/App.js: -------------------------------------------------------------------------------- 1 | import Routing from "./routing/routing.jsx" 2 | 3 | function App() { 4 | return ( 5 | <> 6 | 7 | 8 | ); 9 | } 10 | 11 | export default App; 12 | -------------------------------------------------------------------------------- /Grand Hackathon/client/src/App.test.js: -------------------------------------------------------------------------------- 1 | import { render, screen } from '@testing-library/react'; 2 | import App from './App'; 3 | 4 | test('renders learn react link', () => { 5 | render(); 6 | const linkElement = screen.getByText(/learn react/i); 7 | expect(linkElement).toBeInTheDocument(); 8 | }); 9 | -------------------------------------------------------------------------------- /Grand Hackathon/client/src/assets/banner-image.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/arhamansari11/Backend-Developement/f0765184454f09164178677f8fb0c52ef40c64b4/Grand Hackathon/client/src/assets/banner-image.jpg -------------------------------------------------------------------------------- /Grand Hackathon/client/src/assets/docter.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/arhamansari11/Backend-Developement/f0765184454f09164178677f8fb0c52ef40c64b4/Grand Hackathon/client/src/assets/docter.jpg -------------------------------------------------------------------------------- /Grand Hackathon/client/src/assets/icon02-free-img.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/arhamansari11/Backend-Developement/f0765184454f09164178677f8fb0c52ef40c64b4/Grand Hackathon/client/src/assets/icon02-free-img.png -------------------------------------------------------------------------------- /Grand Hackathon/client/src/assets/icon03-free-img.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/arhamansari11/Backend-Developement/f0765184454f09164178677f8fb0c52ef40c64b4/Grand Hackathon/client/src/assets/icon03-free-img.png -------------------------------------------------------------------------------- /Grand Hackathon/client/src/assets/icon04-free-img.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/arhamansari11/Backend-Developement/f0765184454f09164178677f8fb0c52ef40c64b4/Grand Hackathon/client/src/assets/icon04-free-img.png -------------------------------------------------------------------------------- /Grand Hackathon/client/src/assets/icon05-free-img.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/arhamansari11/Backend-Developement/f0765184454f09164178677f8fb0c52ef40c64b4/Grand Hackathon/client/src/assets/icon05-free-img.png -------------------------------------------------------------------------------- /Grand Hackathon/client/src/assets/icon06-free-img.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/arhamansari11/Backend-Developement/f0765184454f09164178677f8fb0c52ef40c64b4/Grand Hackathon/client/src/assets/icon06-free-img.png -------------------------------------------------------------------------------- /Grand Hackathon/client/src/assets/logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/arhamansari11/Backend-Developement/f0765184454f09164178677f8fb0c52ef40c64b4/Grand Hackathon/client/src/assets/logo.png -------------------------------------------------------------------------------- /Grand Hackathon/client/src/components/center.jsx: -------------------------------------------------------------------------------- 1 | import React from "react"; 2 | import "../styles/Center.css"; 3 | import Doctor from "../assets/docter.jpg"; 4 | import { Link } from "react-router-dom"; 5 | import Image from "../assets/banner-image.jpg" 6 | 7 | const Center = () => { 8 | return ( 9 |
10 |
11 |
12 |
13 |
14 |

Your Oral Health Matters to Us

15 |

16 | Get a Brighter Smile from London's Best Dentists 17 |

18 | 19 | 22 | 23 |
24 |
25 | Doctor 26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |

34 | Get a Dazzling Smile in Lowest Price 35 |

36 |
37 |
38 |
39 |
40 |

41 | Lorem ipsum dolor, sit amet consectetur adipisicing elit. Vitae 42 | tenetur nisi nihil illum eligendi eum esse aut accusamus. 43 | Obcaecati praesentium facilis nisi ullam culpa ipsum saepe 44 | veritatis recusandae, nemo non.lorem ipsum and then 45 |

46 |
47 |
48 |
49 |
50 | 51 | 54 | 55 |
56 |
57 |
58 |
59 |
60 |
61 |
62 | 63 |
64 |
Card title
65 |

66 | Some quick example text to build on the card title and make up 67 | the bulk of the card's content. 68 |

69 | 70 | Go somewhere 71 | 72 |
73 |
74 |
75 |
76 |
77 | 78 |
79 |
Card title
80 |

81 | Some quick example text to build on the card title and make up 82 | the bulk of the card's content. 83 |

84 | 85 | Go somewhere 86 | 87 |
88 |
89 |
90 |
91 |
92 | 93 |
94 |
Card title
95 |

96 | Some quick example text to build on the card title and make up 97 | the bulk of the card's content. 98 |

99 | 100 | Go somewhere 101 | 102 |
103 |
104 |
105 |
106 |
107 | 108 |
109 |
Card title
110 |

111 | Some quick example text to build on the card title and make up 112 | the bulk of the card's content. 113 |

114 | 115 | Go somewhere 116 | 117 |
118 |
119 |
120 |
121 |
122 |
123 | ); 124 | }; 125 | 126 | export default Center; 127 | -------------------------------------------------------------------------------- /Grand Hackathon/client/src/components/navbar.jsx: -------------------------------------------------------------------------------- 1 | import React from "react"; 2 | import image from "../assets/logo.png"; 3 | import { Link } from "react-router-dom"; 4 | 5 | const Navbar = () => { 6 | return ( 7 | <> 8 | 60 | 61 | ); 62 | }; 63 | 64 | export default Navbar; 65 | -------------------------------------------------------------------------------- /Grand Hackathon/client/src/index.css: -------------------------------------------------------------------------------- 1 | body { 2 | margin: 0; 3 | font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', 'Oxygen', 4 | 'Ubuntu', 'Cantarell', 'Fira Sans', 'Droid Sans', 'Helvetica Neue', 5 | sans-serif; 6 | -webkit-font-smoothing: antialiased; 7 | -moz-osx-font-smoothing: grayscale; 8 | } 9 | 10 | code { 11 | font-family: source-code-pro, Menlo, Monaco, Consolas, 'Courier New', 12 | monospace; 13 | } 14 | -------------------------------------------------------------------------------- /Grand Hackathon/client/src/index.js: -------------------------------------------------------------------------------- 1 | import React from 'react'; 2 | import ReactDOM from 'react-dom/client'; 3 | import './index.css'; 4 | import App from './App'; 5 | import reportWebVitals from './reportWebVitals'; 6 | import { BrowserRouter } from "react-router-dom"; 7 | 8 | 9 | const root = ReactDOM.createRoot(document.getElementById('root')); 10 | root.render( 11 | 12 | 13 | 14 | 15 | 16 | ); 17 | 18 | // If you want to start measuring performance in your app, pass a function 19 | // to log results (for example: reportWebVitals(console.log)) 20 | // or send to an analytics endpoint. Learn more: https://bit.ly/CRA-vitals 21 | reportWebVitals(); 22 | -------------------------------------------------------------------------------- /Grand Hackathon/client/src/pages/About.jsx: -------------------------------------------------------------------------------- 1 | import React from "react"; 2 | import Navbar from "../components/navbar"; 3 | const About = () => { 4 | return ( 5 | <> 6 | 7 |
About
8 | 9 | ); 10 | }; 11 | 12 | export default About; 13 | -------------------------------------------------------------------------------- /Grand Hackathon/client/src/pages/Allapointment.jsx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/arhamansari11/Backend-Developement/f0765184454f09164178677f8fb0c52ef40c64b4/Grand Hackathon/client/src/pages/Allapointment.jsx -------------------------------------------------------------------------------- /Grand Hackathon/client/src/pages/Appointment.jsx: -------------------------------------------------------------------------------- 1 | import React, { useState } from "react"; 2 | import Navbar from "../components/navbar"; 3 | import { toast, ToastContainer } from 'react-toastify'; 4 | import 'react-toastify/dist/ReactToastify.css'; 5 | import "../styles/appoi.css"; // Make sure to import your CSS file 6 | 7 | const Appointment = () => { 8 | const [loginData, setLoginData] = useState({ 9 | name: "", 10 | email: "", 11 | phone: "", 12 | }); 13 | 14 | const handleChange = (e) => { 15 | setLoginData({ 16 | ...loginData, 17 | [e.target.name]: e.target.value, 18 | }); 19 | }; 20 | 21 | const handleSubmit = (e) => { 22 | e.preventDefault(); 23 | 24 | // Log the data to the console 25 | console.log("Form data submitted:", loginData); 26 | 27 | // Show a toast 28 | toast.success('Form Submitted!', { 29 | position: "top-right", 30 | autoClose: 5000, 31 | hideProgressBar: false, 32 | closeOnClick: true, 33 | pauseOnHover: true, 34 | draggable: true, 35 | progress: undefined, 36 | theme: "dark", 37 | }); 38 | 39 | // Reset the input fields 40 | setLoginData({ 41 | name: "", 42 | email: "", 43 | phone: "", 44 | }); 45 | 46 | // Your login logic goes here 47 | // If you want to perform additional actions or send the data to the server, you can do it here 48 | }; 49 | 50 | return ( 51 | <> 52 | 53 |
54 |
55 |
56 | 57 |
58 |
59 |
60 |
61 |

Appointment 👏

62 |

Please enter your details!

63 |
64 |
65 |
66 | 67 | 75 |
76 |
77 | 78 | 86 |
87 |
88 | 89 | 97 |
98 | 101 |
102 |
103 | Please fill out all inputs fields! 104 | and also fill it carefully. 105 |
106 |
107 |
108 |
109 |
110 |
111 |
112 | 113 |
114 |
115 |
116 | 117 | 118 | ); 119 | }; 120 | 121 | export default Appointment; 122 | -------------------------------------------------------------------------------- /Grand Hackathon/client/src/pages/Doctor.jsx: -------------------------------------------------------------------------------- 1 | import React, { useState, useEffect } from "react"; 2 | import { Link } from "react-router-dom"; 3 | import Navbar from "../components/navbar"; 4 | import axios from "axios"; 5 | 6 | const Doctor = () => { 7 | const [doctors, setDoctors] = useState([]); 8 | 9 | // GET DATA 10 | const getDoctors = async () => { 11 | const doctorList = await axios.get("http://localhost:8080/"); 12 | setDoctors(doctorList.data); 13 | }; 14 | 15 | useEffect(() => { 16 | getDoctors(); 17 | }, []); 18 | 19 | return ( 20 | <> 21 | 22 | 23 |

27 | Our All Doctors 28 |

29 |
30 |
31 |
32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | {doctors.map((doctor) => ( 43 | 44 | 45 | 46 | 47 | 60 | 61 | ))} 62 | 63 |
NameSpecializationContact InfoActions
{doctor.name}{doctor.specialization}{doctor.contactinfo} 48 | {/* Pass the doctor data to the Appointment component */} 49 | 55 | 58 | 59 |
64 |
65 |
66 |
67 | 68 | ); 69 | }; 70 | 71 | export default Doctor; 72 | -------------------------------------------------------------------------------- /Grand Hackathon/client/src/pages/Error.jsx: -------------------------------------------------------------------------------- 1 | import React from 'react' 2 | import Navbar from "../components/navbar"; 3 | const Error = () => { 4 | return ( 5 |
6 | 7 |

Error

8 |

404 Page Not Found

9 |
10 | ) 11 | } 12 | 13 | export default Error -------------------------------------------------------------------------------- /Grand Hackathon/client/src/pages/Home.jsx: -------------------------------------------------------------------------------- 1 | import React from 'react' 2 | import Navbar from "../components/navbar"; 3 | import Center from "../components/center" 4 | 5 | const Home = () => { 6 | return ( 7 | <> 8 | 9 |
10 | 11 | ) 12 | } 13 | 14 | export default Home -------------------------------------------------------------------------------- /Grand Hackathon/client/src/pages/OurDoctors.jsx: -------------------------------------------------------------------------------- 1 | import React, { useState, useEffect } from "react"; 2 | import Navbar from "../components/navbar"; 3 | import axios from "axios"; 4 | 5 | const initialstate = { 6 | name: "", 7 | specialization: "", 8 | contactinfo: "", 9 | schedule: [], // Added schedule field 10 | }; 11 | 12 | const Doctor = () => { 13 | const [doctors, setDoctors] = useState([]); 14 | const [newDoctor, setNewDoctor] = useState(initialstate); 15 | const [selectedDoctor, setSelectedDoctor] = useState(null); 16 | const [updatedData, setUpdatedData] = useState(initialstate); 17 | 18 | // GET DATA 19 | const getDoctors = async () => { 20 | const doctorList = await axios.get("http://localhost:8080/"); 21 | setDoctors(doctorList.data); 22 | }; 23 | 24 | useEffect(() => { 25 | getDoctors(); 26 | }, []); 27 | 28 | // POST DATA and UPDATE DATA 29 | const handleChange = (e) => { 30 | const dataToUpdate = selectedDoctor ? updatedData : newDoctor; 31 | 32 | if (selectedDoctor) { 33 | setUpdatedData({ 34 | ...dataToUpdate, 35 | [e.target.name]: e.target.value, 36 | }); 37 | } else { 38 | setNewDoctor({ 39 | ...dataToUpdate, 40 | [e.target.name]: e.target.value, 41 | }); 42 | } 43 | }; 44 | 45 | const handleSubmit = async (e) => { 46 | e.preventDefault(); 47 | 48 | if (selectedDoctor) { 49 | await axios.put( 50 | `http://localhost:8080/updDr/${selectedDoctor._id}`, 51 | updatedData 52 | ); 53 | } else { 54 | await axios.post("http://localhost:8080/addDr", newDoctor); 55 | } 56 | 57 | getDoctors(); 58 | 59 | setSelectedDoctor(null); 60 | setUpdatedData(initialstate); 61 | setNewDoctor(initialstate); 62 | }; 63 | 64 | // DELETE DATA 65 | const handleDelete = async (doctorId) => { 66 | await axios.delete(`http://localhost:8080/delDr/${doctorId}`); 67 | getDoctors(); 68 | }; 69 | 70 | // UPDATE DATA 71 | const handleUpdate = (doctor) => { 72 | setSelectedDoctor(doctor); 73 | setUpdatedData({ 74 | name: doctor.name, 75 | specialization: doctor.specialization, 76 | contactinfo: doctor.contactinfo, 77 | schedule: doctor.schedule, // Added schedule 78 | }); 79 | }; 80 | 81 | return ( 82 | <> 83 | 84 | 85 |

89 | Add Doctor 90 |

91 |
92 |
93 |
94 | {/* Form for adding or updating data */} 95 |
96 | 99 | 107 | 108 | 111 | 121 | 122 | 125 | 133 | 134 | {/* Additional fields for schedule */} 135 | {/* You can add input fields for schedule as needed */} 136 | 137 | 140 |
141 | 142 |

146 | All Doctors Data 147 |

148 | 149 | 150 | 151 | 152 | 153 | 154 | 155 | 156 | 157 | 158 | {doctors.map((doctor) => ( 159 | 160 | 161 | 162 | 163 | 177 | 178 | ))} 179 | 180 |
NameSpecializationContact InfoActions
{doctor.name}{doctor.specialization}{doctor.contactinfo} 164 | 170 | 176 |
181 |
182 |
183 |
184 | 185 | ); 186 | }; 187 | 188 | export default Doctor; 189 | -------------------------------------------------------------------------------- /Grand Hackathon/client/src/pages/Pateints.jsx: -------------------------------------------------------------------------------- 1 | import React from "react"; 2 | import Navbar from "../components/navbar"; 3 | const Pateints = () => { 4 | return ( 5 | <> 6 | 7 |
Pateints
8 | 9 | ); 10 | }; 11 | 12 | export default Pateints; 13 | -------------------------------------------------------------------------------- /Grand Hackathon/client/src/reportWebVitals.js: -------------------------------------------------------------------------------- 1 | const reportWebVitals = onPerfEntry => { 2 | if (onPerfEntry && onPerfEntry instanceof Function) { 3 | import('web-vitals').then(({ getCLS, getFID, getFCP, getLCP, getTTFB }) => { 4 | getCLS(onPerfEntry); 5 | getFID(onPerfEntry); 6 | getFCP(onPerfEntry); 7 | getLCP(onPerfEntry); 8 | getTTFB(onPerfEntry); 9 | }); 10 | } 11 | }; 12 | 13 | export default reportWebVitals; 14 | -------------------------------------------------------------------------------- /Grand Hackathon/client/src/routing/routing.jsx: -------------------------------------------------------------------------------- 1 | import React from 'react' 2 | import { Routes , Route } from 'react-router-dom' 3 | import Home from "../pages/Home" 4 | import Doctor from "../pages/Doctor" 5 | import About from "../pages/About" 6 | import Pateints from "../pages/Pateints" 7 | import Error from "../pages/Error" 8 | import Appointment from "../pages/Appointment" 9 | import Ourdoctors from "../pages/OurDoctors" 10 | import Allapointment from "../pages/Allapointment" 11 | 12 | const Routing = () => { 13 | return ( 14 | 15 | 16 | }/> 17 | }/> 18 | }/> 19 | }/> 20 | }/> 21 | }/> 22 | }/> 23 | }/> 24 | 25 | 26 | ) 27 | } 28 | 29 | export default Routing -------------------------------------------------------------------------------- /Grand Hackathon/client/src/setupTests.js: -------------------------------------------------------------------------------- 1 | // jest-dom adds custom jest matchers for asserting on DOM nodes. 2 | // allows you to do things like: 3 | // expect(element).toHaveTextContent(/react/i) 4 | // learn more: https://github.com/testing-library/jest-dom 5 | import '@testing-library/jest-dom'; 6 | -------------------------------------------------------------------------------- /Grand Hackathon/client/src/styles/Center.css: -------------------------------------------------------------------------------- 1 | .bg-color{ 2 | background-color: #106CA0; 3 | } 4 | .clr{ 5 | color: white; 6 | border-color: white; 7 | } 8 | .clr:hover{ 9 | background-color: white; 10 | color: black; 11 | } 12 | .heading{ 13 | font-size: 30; 14 | font-weight: bolder; 15 | } 16 | .img-set>img{ 17 | height: 500px; 18 | width: 340px; 19 | } 20 | .fs-h1{ 21 | font-weight: bolder; 22 | color: white; 23 | } 24 | .sc-h1{ 25 | font-weight: bolder; 26 | color: white; 27 | display: flex; 28 | justify-content: center; 29 | align-items: center; 30 | } 31 | .class{ 32 | display: flex; 33 | justify-content:space-around; 34 | align-items: center; 35 | } 36 | 37 | @media only screen and (min-width:768px) and (max-width:992px){ 38 | .img-set>img{ 39 | height: 450px; 40 | width: 300px; 41 | } 42 | .fs-h1{ 43 | font-size: 30px; 44 | color: white; 45 | } 46 | .sc-h1{ 47 | font-size: 30px; 48 | color: white; 49 | display: flex; 50 | justify-content: center; 51 | align-items: center; 52 | } 53 | } 54 | @media only screen and (min-width:550px) and (max-width:767px){ 55 | .img-set>img{ 56 | height: 420px; 57 | width: 280px; 58 | } 59 | .fs-h1{ 60 | font-size: 17px; 61 | color: white; 62 | } 63 | .sc-h1{ 64 | font-size: 17px; 65 | color: white; 66 | display: flex; 67 | justify-content: center; 68 | align-items: center; 69 | } 70 | } 71 | @media only screen and (min-width:340px) and (max-width:549px){ 72 | .img-set>img{ 73 | height: 300px; 74 | width: 220px; 75 | } 76 | .fs-h1{ 77 | font-size: 15px; 78 | color: white; 79 | } 80 | .sc-h1{ 81 | font-size: 15px; 82 | color: white; 83 | display: flex; 84 | justify-content: center; 85 | align-items: center; 86 | } 87 | } -------------------------------------------------------------------------------- /Grand Hackathon/client/src/styles/appoi.css: -------------------------------------------------------------------------------- 1 | 2 | 3 | @import url('https://fonts.googleapis.com/css2?family=Mulish&display=swap'); 4 | 5 | :root { 6 | --primary: #4978F0; 7 | --primary-light: #E1EEF5; 8 | --secondary: #1D1D1D; 9 | --background: #F4F1FF; 10 | --text: #1F2346; 11 | } 12 | 13 | body { 14 | font-size: 16px; 15 | margin: 0px !important ; 16 | } 17 | 18 | 19 | * { 20 | margin: 0; 21 | padding: 0; 22 | box-sizing: border-box; 23 | font-family: Mulish; 24 | } 25 | 26 | .socials-row { 27 | display: flex; 28 | gap: 16px; 29 | flex-wrap: wrap; 30 | } 31 | 32 | .socials-row img { 33 | width: 24px; 34 | height: 24px; 35 | } 36 | 37 | .socials-row > a { 38 | padding: 8px; 39 | border-radius: 8px; 40 | width: 100%; 41 | min-height: 48px; 42 | display: flex; 43 | gap: 12px; 44 | justify-content: center; 45 | align-items: center; 46 | text-decoration: none; 47 | font-size: 1.1rem; 48 | color: var(--text); 49 | padding: 8px; 50 | border: 1px solid var(--primary-light); 51 | font-weight: 700; 52 | } 53 | 54 | .socials-row > a:hover { 55 | border: 1px solid var(--primary); 56 | } 57 | 58 | .divider { 59 | display: flex; 60 | flex-direction: row; 61 | color: var(--secondary); 62 | gap: 16px; 63 | align-items: center; 64 | } 65 | 66 | .divider-line { 67 | width: 100%; 68 | height: 1px; 69 | background-color: var(--secondary); 70 | opacity: .2; 71 | } 72 | 73 | .login-wrapper { 74 | position: relative; 75 | display: grid; 76 | grid-template-columns: 4fr 3fr; 77 | max-width: 1200px; 78 | margin: 0 auto; 79 | } 80 | 81 | 82 | .login-side { 83 | /* padding: 188px 32px 48px 32px; */ 84 | display: flex; 85 | justify-content: center; 86 | align-items: start; 87 | } 88 | 89 | .info-side { 90 | /* height: 100vh; */ 91 | /* padding: 84px 48px 48px 32px; */ 92 | color: #401B3D; 93 | display: flex; 94 | overflow: hidden; 95 | flex-direction: column; 96 | justify-content: start; 97 | align-items: center; 98 | background-color: var(--background); 99 | } 100 | 101 | .info-side h2 { 102 | margin-top: 48px; 103 | color: var(--text); 104 | font-size: 1.8rem; 105 | margin-bottom: 12px; 106 | } 107 | 108 | .info-side p { 109 | font-size: 1.2rem; 110 | } 111 | 112 | .info-side img { 113 | max-width: 860px; 114 | } 115 | 116 | .welcome-message { 117 | max-width: 360px; 118 | } 119 | 120 | .logo { 121 | height: 48px; 122 | position: absolute; 123 | top: 20px; 124 | left: 20px; 125 | } 126 | 127 | .my-form__wrapper { 128 | border-radius: 10px; 129 | display: flex; 130 | flex-direction: column; 131 | align-items: center; 132 | gap: 32px; 133 | max-width: 460px; 134 | width: 100%; 135 | padding: 48px 32px; 136 | height: fit-content; 137 | box-shadow: rgba(45, 45, 132, 0.2) 0px 7px 29px 0px; 138 | background-color: white; /* Set background color to white */ 139 | } 140 | 141 | 142 | .my-form { 143 | display: flex; 144 | flex-direction: column; 145 | justify-content: start; 146 | position: relative; 147 | gap: 16px; 148 | } 149 | 150 | .login-welcome { 151 | height: 80px; 152 | width: 80px; 153 | border-radius: 50%; 154 | object-fit: cover; 155 | } 156 | 157 | .login-welcome-row { 158 | display: flex; 159 | width: 100%; 160 | flex-direction: column; 161 | gap: 8px; 162 | } 163 | 164 | .my-form__button { 165 | background-color: var(--primary); 166 | color: white; 167 | white-space: nowrap; 168 | border: none; 169 | display: flex; 170 | justify-content: center; 171 | align-items: center; 172 | margin-top: 16px; 173 | line-height: 50px; 174 | outline: none; 175 | font-size: 18px; 176 | letter-spacing: .025em; 177 | text-decoration: none; 178 | cursor: pointer; 179 | font-weight: 800; 180 | min-height: 50px; 181 | width: 100%; 182 | border-radius: 8px; 183 | box-shadow: 0 5px 10px rgba(0,0,0,.15); 184 | transition: all .3s ease; 185 | -webkit-transition: all .3s ease; 186 | } 187 | 188 | .my-form__actions { 189 | display: flex; 190 | flex-direction: column; 191 | color: var(--secondary); 192 | gap: 16px; 193 | margin-top: 8px; 194 | } 195 | 196 | .my-form__actions a { 197 | color: var(--secondary); 198 | font-weight: 600; 199 | text-decoration: none; 200 | } 201 | 202 | .my-form__actions a:hover { 203 | text-decoration: underline; 204 | } 205 | 206 | .my-form__row { 207 | display: flex; 208 | justify-content: space-between; 209 | } 210 | 211 | .my-form__signup { 212 | display: flex; 213 | justify-content: center; 214 | } 215 | 216 | .my-form__signup a { 217 | color: var(--primary); 218 | font-weight: 800; 219 | text-decoration: none; 220 | font-size: 18px; 221 | } 222 | 223 | .my-form__signup a:hover { 224 | text-decoration: underline; 225 | } 226 | 227 | .text-field input { 228 | color: var(--secondary); 229 | font-size: 16px; 230 | font-weight: 500; 231 | max-width: 100%; 232 | width: 100%; 233 | border: 1px solid var(--secondary); 234 | height: 50px; 235 | letter-spacing: .03rem; 236 | background-color: transparent; 237 | outline: none; 238 | transition: .25s; 239 | border-radius: 8px; 240 | text-indent: 20px; 241 | margin-top: 8px; 242 | } 243 | 244 | .text-field { 245 | position: relative; 246 | } 247 | 248 | .text-field img { 249 | position: absolute; 250 | right: -2px; 251 | bottom: -4px; 252 | width: 30px; 253 | height: 30px; 254 | transform: translate(-50%,-50%); 255 | transform-origin: center; 256 | } 257 | 258 | .text-field input:focus { 259 | border: 1px solid var(--primary); 260 | } 261 | 262 | .text-field label { 263 | color: var(--secondary); 264 | font-size: 14px; 265 | font-weight: 600; 266 | letter-spacing: .03rem; 267 | z-index: 10; 268 | } 269 | 270 | @media (max-width: 640px) { 271 | .login-wrapper { 272 | grid-template-columns: 1fr; 273 | height: 100vh; 274 | } 275 | 276 | .info-side { 277 | flex-direction: column-reverse; 278 | padding: 48px 48px 48px 32px; 279 | } 280 | } 281 | -------------------------------------------------------------------------------- /Grand Hackathon/client/src/todoapp.jsx: -------------------------------------------------------------------------------- 1 | import React, { useState, useEffect } from "react"; 2 | import axios from "axios"; 3 | const initialstate = { 4 | title: "", 5 | task: "", 6 | }; 7 | 8 | const Todoapp = () => { 9 | const [task, setTask] = useState([]); 10 | const [newtask, setNewtask] = useState(initialstate); 11 | const [selectedUser, setSelectedUser] = useState(null); 12 | const [updatedData, setUpdatedData] = useState(initialstate); 13 | 14 | // GET DATA 15 | const getdata = async () => { 16 | const tasks = await axios.get("http://localhost:8080/"); 17 | setTask(tasks.data); 18 | }; 19 | 20 | useEffect(() => { 21 | getdata(); 22 | }, []); 23 | 24 | // POST DATA and UPDATE DATA 25 | const handleChange = (e) => { 26 | const dataToUpdate = selectedUser ? updatedData : newtask; 27 | 28 | if (selectedUser) { 29 | setUpdatedData({ 30 | ...dataToUpdate, 31 | [e.target.name]: e.target.value, 32 | }); 33 | } else { 34 | setNewtask({ 35 | ...dataToUpdate, 36 | [e.target.name]: e.target.value, 37 | }); 38 | } 39 | }; 40 | 41 | const handleSubmit = async (e) => { 42 | e.preventDefault(); 43 | 44 | if (selectedUser) { 45 | await axios.put( 46 | `http://localhost:8080/updTask/${selectedUser._id}`, 47 | updatedData 48 | ); 49 | } else { 50 | await axios.post("http://localhost:8080/addTask", newtask); 51 | } 52 | 53 | getdata(); 54 | 55 | setSelectedUser(null); 56 | setUpdatedData(initialstate); 57 | setNewtask(initialstate); 58 | }; 59 | 60 | // DELETE DATA 61 | 62 | const handleDelete = async (userid) => { 63 | await axios.delete(`http://localhost:8080/delTask/${userid}`); 64 | getdata(); 65 | }; 66 | 67 | // UPDATE DATA 68 | 69 | const handleUpdate = (task) => { 70 | setSelectedUser(task); 71 | setUpdatedData({ 72 | title: task.title, 73 | task: task.task, 74 | }); 75 | }; 76 | 77 | return ( 78 | <> 79 |

83 | Todo App 84 |

85 |
86 |
87 |
88 |
89 | 92 |
93 | 102 |
103 | 106 |
107 | 116 |
117 | 120 |
121 |
122 |
123 |
124 |

128 | Todo App Data 129 |

130 |
131 |
132 |
133 | 134 | 135 | 136 | 137 | 138 | 139 | 140 | 141 | 142 | {task.map((tasks) => ( 143 | 144 | 145 | 146 | 160 | 161 | ))} 162 | 163 |
TitleTaskActions
{tasks.title}{tasks.task} 147 | 153 | 159 |
164 |
165 |
166 |
167 | 168 | ); 169 | }; 170 | 171 | export default Todoapp; 172 | -------------------------------------------------------------------------------- /Grand Hackathon/server/.gitignore: -------------------------------------------------------------------------------- 1 | node_modules 2 | .env -------------------------------------------------------------------------------- /Grand Hackathon/server/index.js: -------------------------------------------------------------------------------- 1 | const express = require('express'); 2 | const moongose = require('mongoose') 3 | const server = express(); 4 | const routing = require('./routes/drroutes') 5 | const approuting = require('./routes/aproutes') 6 | const cors = require("cors"); 7 | require("dotenv").config(); 8 | 9 | moongose.connect(process.env.CONNECTION_STRING, { 10 | useNewUrlParser: true, 11 | useUnifiedTopology: true, 12 | }) 13 | 14 | const db = moongose.connection; 15 | 16 | // Body Parser 17 | server.use(cors()); 18 | server.use(express.json()); 19 | server.use('/',routing) 20 | server.use('/api',approuting) 21 | 22 | db.on("error", (error) => { 23 | console.log("Mongodb error : ", error); 24 | }); 25 | 26 | // 2- scenario when mongodb connected 27 | 28 | db.once("open", () => { 29 | console.log("Mongodb connected sucessfully!"); 30 | const port = process.env.PORT; 31 | server.listen(port, () => { 32 | console.log(`server is running on ${port} port`); 33 | }); 34 | }); 35 | -------------------------------------------------------------------------------- /Grand Hackathon/server/models/appointment.js: -------------------------------------------------------------------------------- 1 | const mongoose = require('mongoose'); 2 | const appointmentSchema = new mongoose.Schema({ 3 | _id: mongoose.Schema.ObjectId, 4 | name: { 5 | type: String, 6 | required: true 7 | }, 8 | phone: { 9 | type: Number, 10 | required: true 11 | }, 12 | email: { 13 | type: String, 14 | required: true, 15 | unique: true 16 | } 17 | }, 18 | { collection: "appointment", versionKey: false }); 19 | 20 | const Appointment = mongoose.model('appointment', appointmentSchema); 21 | module.exports = Appointment; 22 | -------------------------------------------------------------------------------- /Grand Hackathon/server/models/doctor.js: -------------------------------------------------------------------------------- 1 | const mongoose = require('mongoose'); 2 | 3 | // Define the subcollection schema 4 | const appointmentSchema = new mongoose.Schema({ 5 | day: { 6 | type: String, 7 | required: true 8 | }, 9 | time: { 10 | type: String, 11 | required: true 12 | } 13 | }, { _id: false }); 14 | 15 | // Define the main schema 16 | const drSchema = new mongoose.Schema({ 17 | _id: mongoose.Schema.ObjectId, 18 | name: { 19 | type: String, 20 | required: true 21 | }, 22 | specialization: { 23 | type: String, 24 | required: true 25 | }, 26 | contactinfo: { 27 | type: String, 28 | required: true, 29 | unique: true, 30 | }, 31 | schedule: [appointmentSchema] // Fixed typo here (shedule to schedule) 32 | }, { collection: "doctor", versionKey: false }); 33 | 34 | const Doctor = mongoose.model('doctor', drSchema); 35 | 36 | module.exports = Doctor; 37 | -------------------------------------------------------------------------------- /Grand Hackathon/server/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "server", 3 | "version": "1.0.0", 4 | "description": "", 5 | "main": "index.js", 6 | "scripts": { 7 | "start":"nodemon index.js", 8 | "test": "echo \"Error: no test specified\" && exit 1" 9 | }, 10 | "keywords": [], 11 | "author": "", 12 | "license": "ISC", 13 | "dependencies": { 14 | "cors": "^2.8.5", 15 | "dotenv": "^16.3.1", 16 | "express": "^4.18.2", 17 | "mongoose": "^8.0.2" 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /Grand Hackathon/server/routes/aproutes.js: -------------------------------------------------------------------------------- 1 | // routes/appointmentRoutes.js 2 | const express = require('express'); 3 | const mongoose = require('mongoose'); 4 | const Router = express.Router(); 5 | const Appointment = require('../models/appointment'); 6 | 7 | // POST DATA 8 | Router.post('/addAppointment', async (req, res) => { 9 | try { 10 | const newAppointment = new Appointment({ 11 | _id: new mongoose.Types.ObjectId(), 12 | name: req.body.name, 13 | phone: req.body.phone, 14 | email: req.body.email 15 | }); 16 | const result = await newAppointment.save(); 17 | res.json(result); 18 | console.log(result); 19 | } catch (error) { 20 | res.status(500).json(error.message || "Internal Server Error"); 21 | } 22 | }); 23 | 24 | // GET DATA 25 | Router.get('/Appointment', async (req, res) => { 26 | try { 27 | const allAppointments = await Appointment.find(); 28 | res.json(allAppointments); 29 | } catch (error) { 30 | res.status(500).json(error.message || "Internal Server Error"); 31 | } 32 | }); 33 | 34 | // DELETE DATA 35 | Router.delete('/delAppointment/:id', async (req, res) => { 36 | try { 37 | const id = req.params.id; 38 | const deleted = await Appointment.findByIdAndDelete(id); 39 | if (!deleted) { 40 | return res.status(404).json("Appointment Not Found"); 41 | } else { 42 | res.json(deleted); 43 | } 44 | } catch (error) { 45 | res.status(500).json(error.message || "Internal Server Error"); 46 | } 47 | }); 48 | 49 | // UPDATE DATA 50 | Router.put('/updAppointment/:id', async (req, res) => { 51 | try { 52 | const id = req.params.id; 53 | const updatedAppointment = { 54 | name: req.body.name, 55 | phone: req.body.phone, 56 | email: req.body.email 57 | }; 58 | const result = await Appointment.findByIdAndUpdate(id, updatedAppointment, { 59 | new: true 60 | }); 61 | if (!result) { 62 | return res.status(404).json("Appointment Not Found"); 63 | } else { 64 | res.json(result); 65 | } 66 | } catch (error) { 67 | res.status(500).json(error.message || "Internal Server Error"); 68 | } 69 | }); 70 | 71 | module.exports = Router; 72 | -------------------------------------------------------------------------------- /Grand Hackathon/server/routes/drroutes.js: -------------------------------------------------------------------------------- 1 | const express = require('express'); 2 | const mongoose = require('mongoose'); 3 | const Router = express.Router(); 4 | const Doctor = require('../models/doctor'); // Import the Doctor model 5 | 6 | // POST DATA 7 | Router.post('/addDr', async (req, res) => { 8 | try { 9 | const newDoctor = new Doctor({ 10 | _id: new mongoose.Types.ObjectId(), 11 | name: req.body.name, 12 | specialization: req.body.specialization, 13 | contactinfo: req.body.contactinfo, 14 | shedule: req.body.shedule // Assuming shedule is an array of appointments 15 | }); 16 | const result = await newDoctor.save(); 17 | res.json(result); 18 | console.log(result); 19 | } catch (error) { 20 | res.status(500).json("Error creating doctor"); 21 | } 22 | }); 23 | 24 | // GET DATA 25 | Router.get('/', async (req, res) => { 26 | try { 27 | const allDoctors = await Doctor.find(); 28 | res.json(allDoctors); 29 | } catch (error) { 30 | res.status(500).json("Error fetching doctors"); 31 | } 32 | }); 33 | 34 | // DELETE DATA 35 | Router.delete('/delDr/:id', async (req, res) => { 36 | try { 37 | const id = req.params.id; 38 | const deleted = await Doctor.findByIdAndDelete(id); 39 | if (!deleted) { 40 | return res.status(404).json("Doctor Not Found"); 41 | } else { 42 | res.json(deleted); 43 | } 44 | } catch (error) { 45 | res.status(500).json("Error deleting doctor"); 46 | } 47 | }); 48 | 49 | // UPDATE DATA 50 | Router.put('/updDr/:id', async (req, res) => { 51 | try { 52 | const id = req.params.id; 53 | const updatedDoctor = { 54 | name: req.body.name, 55 | specialization: req.body.specialization, 56 | contactinfo: req.body.contactinfo, 57 | shedule: req.body.shedule 58 | }; 59 | const result = await Doctor.findByIdAndUpdate(id, updatedDoctor, { 60 | new: true 61 | }); 62 | if (!result) { 63 | return res.status(404).json("Doctor Not Found"); 64 | } else { 65 | res.json(result); 66 | } 67 | } catch (error) { 68 | res.status(500).json("Error updating doctor"); 69 | } 70 | }); 71 | 72 | module.exports = Router; 73 | -------------------------------------------------------------------------------- /Grand Hackathon/server/routes/routes.js: -------------------------------------------------------------------------------- 1 | const express = require('express'); 2 | const moongose = require('mongoose'); 3 | const Router = express.Router(); // Instantiate the router 4 | const todoapp = require('../models/todo'); 5 | 6 | // POST DATA 7 | Router.post('/addTask', async (req, res) => { 8 | try { 9 | const newtask = new todoapp({ 10 | _id: new moongose.Types.ObjectId(), 11 | title: req.body.title, 12 | task: req.body.task 13 | }); 14 | const result = await newtask.save(); 15 | res.json(result); 16 | console.log(result); 17 | } catch (error) { 18 | res.status(500).json("User Not Found"); 19 | } 20 | }); 21 | 22 | // GET DATA 23 | Router.get('/', async (req, res) => { 24 | const alldata = await todoapp.find(); // Add await here 25 | res.json(alldata); 26 | }); 27 | 28 | // DELETE DATA 29 | Router.delete('/delTask/:id', async (req, res) => { // Add :id to the route 30 | try { 31 | const id = req.params.id; 32 | const deleted = await todoapp.findByIdAndDelete(id); // Pass id to findByIdAndDelete 33 | if (!deleted) { 34 | return res.status(404).json("User Not Found"); 35 | } else { 36 | res.json(deleted); 37 | } 38 | } catch (error) { 39 | res.status(500).json(error); 40 | } 41 | }); 42 | 43 | // UPDATE DATA 44 | Router.put('/updTask/:id', async (req, res) => { // Add :id to the route 45 | try { 46 | const id = req.params.id; 47 | const updatedtask = { 48 | title: req.body.title, 49 | task: req.body.task 50 | }; 51 | const result = await todoapp.findByIdAndUpdate(id, updatedtask, { 52 | new: true 53 | }); 54 | if (!result) { 55 | return res.status(404).json("User Not Found"); 56 | } else { 57 | res.json(result); 58 | } 59 | } catch (error) { 60 | return res.status(500).json(error); 61 | } 62 | }); 63 | 64 | module.exports = Router; // Export the instantiated router 65 | -------------------------------------------------------------------------------- /MVC/.gitignore: -------------------------------------------------------------------------------- 1 | node_modules -------------------------------------------------------------------------------- /MVC/README.md: -------------------------------------------------------------------------------- 1 | 2 | ## Chapter 5 - Backend Directory Structure / MVC / Router 3 | 4 | ### [[ Chapter Notes ]] 5 | 6 | MVC (Model-View-Controller) is **a pattern in software design commonly used to implement user interfaces (VIEW), data (MODEL), and controlling logic (CONTROLLER)**. It emphasizes a separation between the software's business logic and display. 7 | 8 | In Our Project this will be : 9 | **Model** - Database Schema's and Business logics and rules 10 | **View** - Server Side Templates (or React front-end) 11 | **Controller** - functions attached to routes for modifying request and sending responses. It's a link between the Model and View. 12 | 13 | **Router** 14 | - These are like mini-application on which you can make set of Routes independently. 15 | - Routers can be attached to main Server App using `server.use(router)` 16 | 17 | Arrange Directory in Server like this : 18 | 19 | **Controllers** - file containing functions which are attached to each route path 20 | **Routes** - files containing routers 21 | **Models** : to be discussed in later chapters 22 | **Views**: to be discussed in later chapters -------------------------------------------------------------------------------- /MVC/controller/product.js: -------------------------------------------------------------------------------- 1 | const fs = require('fs') 2 | const jsondata = JSON.parse(fs.readFileSync('./data.json', 'utf-8')); 3 | const product = jsondata.products; 4 | 5 | exports.createdata = (req, res) => { 6 | console.log(req.body); 7 | product.push(req.body); 8 | res.json(req.body); 9 | } 10 | 11 | exports.getAlldata = (req, res) => { 12 | res.json(product); 13 | console.log("GET API DONE"); 14 | } 15 | 16 | 17 | exports.getdatabyid = (req, res) => { 18 | const id = +req.params.id; 19 | const newpd = product.find(p => p.id === id) 20 | console.log(newpd); 21 | res.json(newpd); 22 | } 23 | exports.replacedata = (req, res) => { 24 | const id = +req.params.id; 25 | const newpdIndex = product.findIndex(p => p.id === id) 26 | product.splice(newpdIndex, 1, { ...req.body, id: id }) 27 | console.log(newpdIndex); 28 | res.status(202).json(); 29 | } 30 | 31 | 32 | exports.updatedata = (req, res) => { 33 | const id = +req.params.id; 34 | const newpdIndex = product.findIndex(p => p.id === id) 35 | const patchdata = product[newpdIndex] 36 | product.splice(newpdIndex, 1, { ...patchdata, ...req.body }) 37 | console.log(newpdIndex); 38 | res.status(202).json(); 39 | } 40 | 41 | exports.deletedata = (req, res) => { 42 | const id = +req.params.id; 43 | const newpdIndex = product.findIndex(p => p.id === id) 44 | const patchdata = product[newpdIndex] 45 | product.splice(newpdIndex, 1) 46 | console.log(newpdIndex); 47 | res.status(202).json(); 48 | } -------------------------------------------------------------------------------- /MVC/data.json: -------------------------------------------------------------------------------- 1 | { 2 | "products": [ 3 | { 4 | "id": 1, 5 | "title": "iPhone 9", 6 | "description": "An apple mobile which is nothing like apple", 7 | "price": 549, 8 | "discountPercentage": 12.96, 9 | "rating": 4.69, 10 | "stock": 94, 11 | "brand": "Apple", 12 | "category": "smartphones", 13 | "thumbnail": "https://i.dummyjson.com/data/products/1/thumbnail.jpg", 14 | "images": [ 15 | "https://i.dummyjson.com/data/products/1/1.jpg", 16 | "https://i.dummyjson.com/data/products/1/2.jpg", 17 | "https://i.dummyjson.com/data/products/1/3.jpg", 18 | "https://i.dummyjson.com/data/products/1/4.jpg", 19 | "https://i.dummyjson.com/data/products/1/thumbnail.jpg" 20 | ] 21 | }, 22 | { 23 | "id": 2, 24 | "title": "iPhone X", 25 | "description": "SIM-Free, Model A19211 6.5-inch Super Retina HD display with OLED technology A12 Bionic chip with ...", 26 | "price": 899, 27 | "discountPercentage": 17.94, 28 | "rating": 4.44, 29 | "stock": 34, 30 | "brand": "Apple", 31 | "category": "smartphones", 32 | "thumbnail": "https://i.dummyjson.com/data/products/2/thumbnail.jpg", 33 | "images": [ 34 | "https://i.dummyjson.com/data/products/2/1.jpg", 35 | "https://i.dummyjson.com/data/products/2/2.jpg", 36 | "https://i.dummyjson.com/data/products/2/3.jpg", 37 | "https://i.dummyjson.com/data/products/2/thumbnail.jpg" 38 | ] 39 | }, 40 | { 41 | "id": 3, 42 | "title": "Samsung Universe 9", 43 | "description": "Samsung's new variant which goes beyond Galaxy to the Universe", 44 | "price": 1249, 45 | "discountPercentage": 15.46, 46 | "rating": 4.09, 47 | "stock": 36, 48 | "brand": "Samsung", 49 | "category": "smartphones", 50 | "thumbnail": "https://i.dummyjson.com/data/products/3/thumbnail.jpg", 51 | "images": ["https://i.dummyjson.com/data/products/3/1.jpg"] 52 | }, 53 | { 54 | "id": 4, 55 | "title": "OPPOF19", 56 | "description": "OPPO F19 is officially announced on April 2021.", 57 | "price": 280, 58 | "discountPercentage": 17.91, 59 | "rating": 4.3, 60 | "stock": 123, 61 | "brand": "OPPO", 62 | "category": "smartphones", 63 | "thumbnail": "https://i.dummyjson.com/data/products/4/thumbnail.jpg", 64 | "images": [ 65 | "https://i.dummyjson.com/data/products/4/1.jpg", 66 | "https://i.dummyjson.com/data/products/4/2.jpg", 67 | "https://i.dummyjson.com/data/products/4/3.jpg", 68 | "https://i.dummyjson.com/data/products/4/4.jpg", 69 | "https://i.dummyjson.com/data/products/4/thumbnail.jpg" 70 | ] 71 | }, 72 | { 73 | "id": 5, 74 | "title": "Huawei P30", 75 | "description": "Huawei’s re-badged P30 Pro New Edition was officially unveiled yesterday in Germany and now the device has made its way to the UK.", 76 | "price": 499, 77 | "discountPercentage": 10.58, 78 | "rating": 4.09, 79 | "stock": 32, 80 | "brand": "Huawei", 81 | "category": "smartphones", 82 | "thumbnail": "https://i.dummyjson.com/data/products/5/thumbnail.jpg", 83 | "images": [ 84 | "https://i.dummyjson.com/data/products/5/1.jpg", 85 | "https://i.dummyjson.com/data/products/5/2.jpg", 86 | "https://i.dummyjson.com/data/products/5/3.jpg" 87 | ] 88 | }, 89 | { 90 | "id": 6, 91 | "title": "MacBook Pro", 92 | "description": "MacBook Pro 2021 with mini-LED display may launch between September, November", 93 | "price": 1749, 94 | "discountPercentage": 11.02, 95 | "rating": 4.57, 96 | "stock": 83, 97 | "brand": "Apple", 98 | "category": "laptops", 99 | "thumbnail": "https://i.dummyjson.com/data/products/6/thumbnail.png", 100 | "images": [ 101 | "https://i.dummyjson.com/data/products/6/1.png", 102 | "https://i.dummyjson.com/data/products/6/2.jpg", 103 | "https://i.dummyjson.com/data/products/6/3.png", 104 | "https://i.dummyjson.com/data/products/6/4.jpg" 105 | ] 106 | }, 107 | { 108 | "id": 7, 109 | "title": "Samsung Galaxy Book", 110 | "description": "Samsung Galaxy Book S (2020) Laptop With Intel Lakefield Chip, 8GB of RAM Launched", 111 | "price": 1499, 112 | "discountPercentage": 4.15, 113 | "rating": 4.25, 114 | "stock": 50, 115 | "brand": "Samsung", 116 | "category": "laptops", 117 | "thumbnail": "https://i.dummyjson.com/data/products/7/thumbnail.jpg", 118 | "images": [ 119 | "https://i.dummyjson.com/data/products/7/1.jpg", 120 | "https://i.dummyjson.com/data/products/7/2.jpg", 121 | "https://i.dummyjson.com/data/products/7/3.jpg", 122 | "https://i.dummyjson.com/data/products/7/thumbnail.jpg" 123 | ] 124 | }, 125 | { 126 | "id": 8, 127 | "title": "Microsoft Surface Laptop 4", 128 | "description": "Style and speed. Stand out on HD video calls backed by Studio Mics. Capture ideas on the vibrant touchscreen.", 129 | "price": 1499, 130 | "discountPercentage": 10.23, 131 | "rating": 4.43, 132 | "stock": 68, 133 | "brand": "Microsoft Surface", 134 | "category": "laptops", 135 | "thumbnail": "https://i.dummyjson.com/data/products/8/thumbnail.jpg", 136 | "images": [ 137 | "https://i.dummyjson.com/data/products/8/1.jpg", 138 | "https://i.dummyjson.com/data/products/8/2.jpg", 139 | "https://i.dummyjson.com/data/products/8/3.jpg", 140 | "https://i.dummyjson.com/data/products/8/4.jpg", 141 | "https://i.dummyjson.com/data/products/8/thumbnail.jpg" 142 | ] 143 | }, 144 | { 145 | "id": 9, 146 | "title": "Infinix INBOOK", 147 | "description": "Infinix Inbook X1 Ci3 10th 8GB 256GB 14 Win10 Grey – 1 Year Warranty", 148 | "price": 1099, 149 | "discountPercentage": 11.83, 150 | "rating": 4.54, 151 | "stock": 96, 152 | "brand": "Infinix", 153 | "category": "laptops", 154 | "thumbnail": "https://i.dummyjson.com/data/products/9/thumbnail.jpg", 155 | "images": [ 156 | "https://i.dummyjson.com/data/products/9/1.jpg", 157 | "https://i.dummyjson.com/data/products/9/2.png", 158 | "https://i.dummyjson.com/data/products/9/3.png", 159 | "https://i.dummyjson.com/data/products/9/4.jpg", 160 | "https://i.dummyjson.com/data/products/9/thumbnail.jpg" 161 | ] 162 | }, 163 | { 164 | "id": 10, 165 | "title": "HP Pavilion 15-DK1056WM", 166 | "description": "HP Pavilion 15-DK1056WM Gaming Laptop 10th Gen Core i5, 8GB, 256GB SSD, GTX 1650 4GB, Windows 10", 167 | "price": 1099, 168 | "discountPercentage": 6.18, 169 | "rating": 4.43, 170 | "stock": 89, 171 | "brand": "HP Pavilion", 172 | "category": "laptops", 173 | "thumbnail": "https://i.dummyjson.com/data/products/10/thumbnail.jpeg", 174 | "images": [ 175 | "https://i.dummyjson.com/data/products/10/1.jpg", 176 | "https://i.dummyjson.com/data/products/10/2.jpg", 177 | "https://i.dummyjson.com/data/products/10/3.jpg", 178 | "https://i.dummyjson.com/data/products/10/thumbnail.jpeg" 179 | ] 180 | }, 181 | { 182 | "id": 11, 183 | "title": "perfume Oil", 184 | "description": "Mega Discount, Impression of Acqua Di Gio by GiorgioArmani concentrated attar perfume Oil", 185 | "price": 13, 186 | "discountPercentage": 8.4, 187 | "rating": 4.26, 188 | "stock": 65, 189 | "brand": "Impression of Acqua Di Gio", 190 | "category": "fragrances", 191 | "thumbnail": "https://i.dummyjson.com/data/products/11/thumbnail.jpg", 192 | "images": [ 193 | "https://i.dummyjson.com/data/products/11/1.jpg", 194 | "https://i.dummyjson.com/data/products/11/2.jpg", 195 | "https://i.dummyjson.com/data/products/11/3.jpg", 196 | "https://i.dummyjson.com/data/products/11/thumbnail.jpg" 197 | ] 198 | }, 199 | { 200 | "id": 12, 201 | "title": "Brown Perfume", 202 | "description": "Royal_Mirage Sport Brown Perfume for Men & Women - 120ml", 203 | "price": 40, 204 | "discountPercentage": 15.66, 205 | "rating": 4, 206 | "stock": 52, 207 | "brand": "Royal_Mirage", 208 | "category": "fragrances", 209 | "thumbnail": "https://i.dummyjson.com/data/products/12/thumbnail.jpg", 210 | "images": [ 211 | "https://i.dummyjson.com/data/products/12/1.jpg", 212 | "https://i.dummyjson.com/data/products/12/2.jpg", 213 | "https://i.dummyjson.com/data/products/12/3.png", 214 | "https://i.dummyjson.com/data/products/12/4.jpg", 215 | "https://i.dummyjson.com/data/products/12/thumbnail.jpg" 216 | ] 217 | }, 218 | { 219 | "id": 13, 220 | "title": "Fog Scent Xpressio Perfume", 221 | "description": "Product details of Best Fog Scent Xpressio Perfume 100ml For Men cool long lasting perfumes for Men", 222 | "price": 13, 223 | "discountPercentage": 8.14, 224 | "rating": 4.59, 225 | "stock": 61, 226 | "brand": "Fog Scent Xpressio", 227 | "category": "fragrances", 228 | "thumbnail": "https://i.dummyjson.com/data/products/13/thumbnail.webp", 229 | "images": [ 230 | "https://i.dummyjson.com/data/products/13/1.jpg", 231 | "https://i.dummyjson.com/data/products/13/2.png", 232 | "https://i.dummyjson.com/data/products/13/3.jpg", 233 | "https://i.dummyjson.com/data/products/13/4.jpg", 234 | "https://i.dummyjson.com/data/products/13/thumbnail.webp" 235 | ] 236 | }, 237 | { 238 | "id": 14, 239 | "title": "Non-Alcoholic Concentrated Perfume Oil", 240 | "description": "Original Al Munakh® by Mahal Al Musk | Our Impression of Climate | 6ml Non-Alcoholic Concentrated Perfume Oil", 241 | "price": 120, 242 | "discountPercentage": 15.6, 243 | "rating": 4.21, 244 | "stock": 114, 245 | "brand": "Al Munakh", 246 | "category": "fragrances", 247 | "thumbnail": "https://i.dummyjson.com/data/products/14/thumbnail.jpg", 248 | "images": [ 249 | "https://i.dummyjson.com/data/products/14/1.jpg", 250 | "https://i.dummyjson.com/data/products/14/2.jpg", 251 | "https://i.dummyjson.com/data/products/14/3.jpg", 252 | "https://i.dummyjson.com/data/products/14/thumbnail.jpg" 253 | ] 254 | }, 255 | { 256 | "id": 15, 257 | "title": "Eau De Perfume Spray", 258 | "description": "Genuine Al-Rehab spray perfume from UAE/Saudi Arabia/Yemen High Quality", 259 | "price": 30, 260 | "discountPercentage": 10.99, 261 | "rating": 4.7, 262 | "stock": 105, 263 | "brand": "Lord - Al-Rehab", 264 | "category": "fragrances", 265 | "thumbnail": "https://i.dummyjson.com/data/products/15/thumbnail.jpg", 266 | "images": [ 267 | "https://i.dummyjson.com/data/products/15/1.jpg", 268 | "https://i.dummyjson.com/data/products/15/2.jpg", 269 | "https://i.dummyjson.com/data/products/15/3.jpg", 270 | "https://i.dummyjson.com/data/products/15/4.jpg", 271 | "https://i.dummyjson.com/data/products/15/thumbnail.jpg" 272 | ] 273 | }, 274 | { 275 | "id": 16, 276 | "title": "Hyaluronic Acid Serum", 277 | "description": "L'Oréal Paris introduces Hyaluron Expert Replumping Serum formulated with 1.5% Hyaluronic Acid", 278 | "price": 19, 279 | "discountPercentage": 13.31, 280 | "rating": 4.83, 281 | "stock": 110, 282 | "brand": "L'Oreal Paris", 283 | "category": "skincare", 284 | "thumbnail": "https://i.dummyjson.com/data/products/16/thumbnail.jpg", 285 | "images": [ 286 | "https://i.dummyjson.com/data/products/16/1.png", 287 | "https://i.dummyjson.com/data/products/16/2.webp", 288 | "https://i.dummyjson.com/data/products/16/3.jpg", 289 | "https://i.dummyjson.com/data/products/16/4.jpg", 290 | "https://i.dummyjson.com/data/products/16/thumbnail.jpg" 291 | ] 292 | }, 293 | { 294 | "id": 17, 295 | "title": "Tree Oil 30ml", 296 | "description": "Tea tree oil contains a number of compounds, including terpinen-4-ol, that have been shown to kill certain bacteria,", 297 | "price": 12, 298 | "discountPercentage": 4.09, 299 | "rating": 4.52, 300 | "stock": 78, 301 | "brand": "Hemani Tea", 302 | "category": "skincare", 303 | "thumbnail": "https://i.dummyjson.com/data/products/17/thumbnail.jpg", 304 | "images": [ 305 | "https://i.dummyjson.com/data/products/17/1.jpg", 306 | "https://i.dummyjson.com/data/products/17/2.jpg", 307 | "https://i.dummyjson.com/data/products/17/3.jpg", 308 | "https://i.dummyjson.com/data/products/17/thumbnail.jpg" 309 | ] 310 | }, 311 | { 312 | "id": 18, 313 | "title": "Oil Free Moisturizer 100ml", 314 | "description": "Dermive Oil Free Moisturizer with SPF 20 is specifically formulated with ceramides, hyaluronic acid & sunscreen.", 315 | "price": 40, 316 | "discountPercentage": 13.1, 317 | "rating": 4.56, 318 | "stock": 88, 319 | "brand": "Dermive", 320 | "category": "skincare", 321 | "thumbnail": "https://i.dummyjson.com/data/products/18/thumbnail.jpg", 322 | "images": [ 323 | "https://i.dummyjson.com/data/products/18/1.jpg", 324 | "https://i.dummyjson.com/data/products/18/2.jpg", 325 | "https://i.dummyjson.com/data/products/18/3.jpg", 326 | "https://i.dummyjson.com/data/products/18/4.jpg", 327 | "https://i.dummyjson.com/data/products/18/thumbnail.jpg" 328 | ] 329 | }, 330 | { 331 | "id": 19, 332 | "title": "Skin Beauty Serum.", 333 | "description": "Product name: rorec collagen hyaluronic acid white face serum riceNet weight: 15 m", 334 | "price": 46, 335 | "discountPercentage": 10.68, 336 | "rating": 4.42, 337 | "stock": 54, 338 | "brand": "ROREC White Rice", 339 | "category": "skincare", 340 | "thumbnail": "https://i.dummyjson.com/data/products/19/thumbnail.jpg", 341 | "images": [ 342 | "https://i.dummyjson.com/data/products/19/1.jpg", 343 | "https://i.dummyjson.com/data/products/19/2.jpg", 344 | "https://i.dummyjson.com/data/products/19/3.png", 345 | "https://i.dummyjson.com/data/products/19/thumbnail.jpg" 346 | ] 347 | }, 348 | { 349 | "id": 20, 350 | "title": "Freckle Treatment Cream- 15gm", 351 | "description": "Fair & Clear is Pakistan's only pure Freckle cream which helpsfade Freckles, Darkspots and pigments. Mercury level is 0%, so there are no side effects.", 352 | "price": 70, 353 | "discountPercentage": 16.99, 354 | "rating": 4.06, 355 | "stock": 140, 356 | "brand": "Fair & Clear", 357 | "category": "skincare", 358 | "thumbnail": "https://i.dummyjson.com/data/products/20/thumbnail.jpg", 359 | "images": [ 360 | "https://i.dummyjson.com/data/products/20/1.jpg", 361 | "https://i.dummyjson.com/data/products/20/2.jpg", 362 | "https://i.dummyjson.com/data/products/20/3.jpg", 363 | "https://i.dummyjson.com/data/products/20/4.jpg", 364 | "https://i.dummyjson.com/data/products/20/thumbnail.jpg" 365 | ] 366 | }, 367 | { 368 | "id": 21, 369 | "title": "- Daal Masoor 500 grams", 370 | "description": "Fine quality Branded Product Keep in a cool and dry place", 371 | "price": 20, 372 | "discountPercentage": 4.81, 373 | "rating": 4.44, 374 | "stock": 133, 375 | "brand": "Saaf & Khaas", 376 | "category": "groceries", 377 | "thumbnail": "https://i.dummyjson.com/data/products/21/thumbnail.png", 378 | "images": [ 379 | "https://i.dummyjson.com/data/products/21/1.png", 380 | "https://i.dummyjson.com/data/products/21/2.jpg", 381 | "https://i.dummyjson.com/data/products/21/3.jpg" 382 | ] 383 | }, 384 | { 385 | "id": 22, 386 | "title": "Elbow Macaroni - 400 gm", 387 | "description": "Product details of Bake Parlor Big Elbow Macaroni - 400 gm", 388 | "price": 14, 389 | "discountPercentage": 15.58, 390 | "rating": 4.57, 391 | "stock": 146, 392 | "brand": "Bake Parlor Big", 393 | "category": "groceries", 394 | "thumbnail": "https://i.dummyjson.com/data/products/22/thumbnail.jpg", 395 | "images": [ 396 | "https://i.dummyjson.com/data/products/22/1.jpg", 397 | "https://i.dummyjson.com/data/products/22/2.jpg", 398 | "https://i.dummyjson.com/data/products/22/3.jpg" 399 | ] 400 | }, 401 | { 402 | "id": 23, 403 | "title": "Orange Essence Food Flavou", 404 | "description": "Specifications of Orange Essence Food Flavour For Cakes and Baking Food Item", 405 | "price": 14, 406 | "discountPercentage": 8.04, 407 | "rating": 4.85, 408 | "stock": 26, 409 | "brand": "Baking Food Items", 410 | "category": "groceries", 411 | "thumbnail": "https://i.dummyjson.com/data/products/23/thumbnail.jpg", 412 | "images": [ 413 | "https://i.dummyjson.com/data/products/23/1.jpg", 414 | "https://i.dummyjson.com/data/products/23/2.jpg", 415 | "https://i.dummyjson.com/data/products/23/3.jpg", 416 | "https://i.dummyjson.com/data/products/23/4.jpg", 417 | "https://i.dummyjson.com/data/products/23/thumbnail.jpg" 418 | ] 419 | }, 420 | { 421 | "id": 24, 422 | "title": "cereals muesli fruit nuts", 423 | "description": "original fauji cereal muesli 250gm box pack original fauji cereals muesli fruit nuts flakes breakfast cereal break fast faujicereals cerels cerel foji fouji", 424 | "price": 46, 425 | "discountPercentage": 16.8, 426 | "rating": 4.94, 427 | "stock": 113, 428 | "brand": "fauji", 429 | "category": "groceries", 430 | "thumbnail": "https://i.dummyjson.com/data/products/24/thumbnail.jpg", 431 | "images": [ 432 | "https://i.dummyjson.com/data/products/24/1.jpg", 433 | "https://i.dummyjson.com/data/products/24/2.jpg", 434 | "https://i.dummyjson.com/data/products/24/3.jpg", 435 | "https://i.dummyjson.com/data/products/24/4.jpg", 436 | "https://i.dummyjson.com/data/products/24/thumbnail.jpg" 437 | ] 438 | }, 439 | { 440 | "id": 25, 441 | "title": "Gulab Powder 50 Gram", 442 | "description": "Dry Rose Flower Powder Gulab Powder 50 Gram • Treats Wounds", 443 | "price": 70, 444 | "discountPercentage": 13.58, 445 | "rating": 4.87, 446 | "stock": 47, 447 | "brand": "Dry Rose", 448 | "category": "groceries", 449 | "thumbnail": "https://i.dummyjson.com/data/products/25/thumbnail.jpg", 450 | "images": [ 451 | "https://i.dummyjson.com/data/products/25/1.png", 452 | "https://i.dummyjson.com/data/products/25/2.jpg", 453 | "https://i.dummyjson.com/data/products/25/3.png", 454 | "https://i.dummyjson.com/data/products/25/4.jpg", 455 | "https://i.dummyjson.com/data/products/25/thumbnail.jpg" 456 | ] 457 | }, 458 | { 459 | "id": 26, 460 | "title": "Plant Hanger For Home", 461 | "description": "Boho Decor Plant Hanger For Home Wall Decoration Macrame Wall Hanging Shelf", 462 | "price": 41, 463 | "discountPercentage": 17.86, 464 | "rating": 4.08, 465 | "stock": 131, 466 | "brand": "Boho Decor", 467 | "category": "home-decoration", 468 | "thumbnail": "https://i.dummyjson.com/data/products/26/thumbnail.jpg", 469 | "images": [ 470 | "https://i.dummyjson.com/data/products/26/1.jpg", 471 | "https://i.dummyjson.com/data/products/26/2.jpg", 472 | "https://i.dummyjson.com/data/products/26/3.jpg", 473 | "https://i.dummyjson.com/data/products/26/4.jpg", 474 | "https://i.dummyjson.com/data/products/26/5.jpg", 475 | "https://i.dummyjson.com/data/products/26/thumbnail.jpg" 476 | ] 477 | }, 478 | { 479 | "id": 27, 480 | "title": "Flying Wooden Bird", 481 | "description": "Package Include 6 Birds with Adhesive Tape Shape: 3D Shaped Wooden Birds Material: Wooden MDF, Laminated 3.5mm", 482 | "price": 51, 483 | "discountPercentage": 15.58, 484 | "rating": 4.41, 485 | "stock": 17, 486 | "brand": "Flying Wooden", 487 | "category": "home-decoration", 488 | "thumbnail": "https://i.dummyjson.com/data/products/27/thumbnail.webp", 489 | "images": [ 490 | "https://i.dummyjson.com/data/products/27/1.jpg", 491 | "https://i.dummyjson.com/data/products/27/2.jpg", 492 | "https://i.dummyjson.com/data/products/27/3.jpg", 493 | "https://i.dummyjson.com/data/products/27/4.jpg", 494 | "https://i.dummyjson.com/data/products/27/thumbnail.webp" 495 | ] 496 | }, 497 | { 498 | "id": 28, 499 | "title": "3D Embellishment Art Lamp", 500 | "description": "3D led lamp sticker Wall sticker 3d wall art light on/off button cell operated (included)", 501 | "price": 20, 502 | "discountPercentage": 16.49, 503 | "rating": 4.82, 504 | "stock": 54, 505 | "brand": "LED Lights", 506 | "category": "home-decoration", 507 | "thumbnail": "https://i.dummyjson.com/data/products/28/thumbnail.jpg", 508 | "images": [ 509 | "https://i.dummyjson.com/data/products/28/1.jpg", 510 | "https://i.dummyjson.com/data/products/28/2.jpg", 511 | "https://i.dummyjson.com/data/products/28/3.png", 512 | "https://i.dummyjson.com/data/products/28/4.jpg", 513 | "https://i.dummyjson.com/data/products/28/thumbnail.jpg" 514 | ] 515 | }, 516 | { 517 | "id": 29, 518 | "title": "Handcraft Chinese style", 519 | "description": "Handcraft Chinese style art luxury palace hotel villa mansion home decor ceramic vase with brass fruit plate", 520 | "price": 60, 521 | "discountPercentage": 15.34, 522 | "rating": 4.44, 523 | "stock": 7, 524 | "brand": "luxury palace", 525 | "category": "home-decoration", 526 | "thumbnail": "https://i.dummyjson.com/data/products/29/thumbnail.webp", 527 | "images": [ 528 | "https://i.dummyjson.com/data/products/29/1.jpg", 529 | "https://i.dummyjson.com/data/products/29/2.jpg", 530 | "https://i.dummyjson.com/data/products/29/3.webp", 531 | "https://i.dummyjson.com/data/products/29/4.webp", 532 | "https://i.dummyjson.com/data/products/29/thumbnail.webp" 533 | ] 534 | }, 535 | { 536 | "id": 30, 537 | "title": "Key Holder", 538 | "description": "Attractive DesignMetallic materialFour key hooksReliable & DurablePremium Quality", 539 | "price": 30, 540 | "discountPercentage": 2.92, 541 | "rating": 4.92, 542 | "stock": 54, 543 | "brand": "Golden", 544 | "category": "home-decoration", 545 | "thumbnail": "https://i.dummyjson.com/data/products/30/thumbnail.jpg", 546 | "images": [ 547 | "https://i.dummyjson.com/data/products/30/1.jpg", 548 | "https://i.dummyjson.com/data/products/30/2.jpg", 549 | "https://i.dummyjson.com/data/products/30/3.jpg", 550 | "https://i.dummyjson.com/data/products/30/thumbnail.jpg" 551 | ] 552 | } 553 | ] 554 | } 555 | -------------------------------------------------------------------------------- /MVC/index.js: -------------------------------------------------------------------------------- 1 | const express = require('express') 2 | const server = express() 3 | const productrouter = require('./routes/routes.js') 4 | 5 | // Body Parser Middlewear 6 | server.use(express.json()); 7 | server.use(express.static("public")); 8 | server.use('/products', productrouter.routing) 9 | 10 | 11 | 12 | //MVS => Model-View-Controller 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | server.listen(8080, () => { 21 | console.log("Server Running on Port 8080"); 22 | }) 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | -------------------------------------------------------------------------------- /MVC/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "node-class-02", 3 | "version": "1.0.0", 4 | "description": "", 5 | "main": "index.js", 6 | "scripts": { 7 | "start": "nodemon index.js", 8 | "test": "echo \"Error: no test specified\" && exit 1" 9 | }, 10 | "keywords": [], 11 | "author": "", 12 | "license": "ISC", 13 | "dependencies": { 14 | "express": "^4.18.2", 15 | "morgan": "^1.10.0" 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /MVC/routes/routes.js: -------------------------------------------------------------------------------- 1 | const express = require('express'); 2 | const controller = require('../controller/product.js') 3 | const router = express.Router(); 4 | 5 | 6 | 7 | router 8 | .post('/', controller.createdata) 9 | .get('/', controller.getAlldata) 10 | .get('/:id', controller.getdatabyid) 11 | .put('/:id', controller.replacedata) 12 | .patch('/:id', controller.updatedata) 13 | .delete('/:id', controller.deletedata) 14 | 15 | exports.routing = router; -------------------------------------------------------------------------------- /MongoDb-Commands/No SQL.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/arhamansari11/Backend-Developement/f0765184454f09164178677f8fb0c52ef40c64b4/MongoDb-Commands/No SQL.png -------------------------------------------------------------------------------- /MongoDb-Commands/README.md: -------------------------------------------------------------------------------- 1 | # Mongo_db_commands 2 | 3 | All MongoDb commands you will ever need (MongoDb Cheatsheet) 4 | In this post, we will see a comprehensive list of all the MongoDB commands you will ever need as a MongoDB beginner. This list covers almost all the most used commands in MongoDB. 5 | 6 | I will assume that you are working inside a collection named 'comments' on a MongoDB database of your choice 7 | 8 | # 1. Database Commands 9 | ## View all databases 10 | show dbs 11 | ## Create a new or switch databases 12 | use dbName 13 | ## View current Database 14 | db 15 | ## Delete Database 16 | db.dropDatabase() 17 | # 2. Collection Commands 18 | ## show collections 19 | ### Create a collection named 'comments' 20 | db.createCollection('comments') 21 | ## Drop a collection named 'comments' 22 | db.comments.drop() 23 | #3. Row(Document) Commands 24 | ## Show all Rows in a Collection 25 | db.comments.find() 26 | ## Show all Rows in a Collection (Prettified) 27 | db.comments.find().pretty() 28 | ## Find the first row matching the object 29 | db.comments.findOne({name: 'Harry'}) 30 | ## Insert One Row 31 | db.comments.insert({ 32 | 'name': 'Harry', 33 | 'lang': 'JavaScript', 34 | 'member_since': 5 35 | }) 36 | ## Insert many Rows 37 | db.comments.insertMany([{ 38 | 'name': 'Harry', 39 | 'lang': 'JavaScript', 40 | 'member_since': 5 41 | }, 42 | {'name': 'Rohan', 43 | 'lang': 'Python', 44 | 'member_since': 3 45 | }, 46 | {'name': 'Lovish', 47 | 'lang': 'Java', 48 | 'member_since': 4 49 | }]) 50 | 51 | ## Search in a MongoDb Database 52 | db.comments.find({lang:'Python'}) 53 | ## Limit the number of rows in output 54 | db.comments.find().limit(2) 55 | ## Count the number of rows in the output 56 | db.comments.find().count() 57 | ## Update a row 58 | db.comments.updateOne({name: 'Shubham'}, 59 | {$set: {'name': 'Harry', 60 | 'lang': 'JavaScript', 61 | 'member_since': 51 62 | }}, {upsert: true}) 63 | ## Mongodb Increment Operator 64 | db.comments.update({name: 'Rohan'}, 65 | {$inc:{ 66 | member_since: 2 67 | }}) 68 | ## Mongodb Rename Operator 69 | db.comments.update({name: 'Rohan'}, 70 | {$rename:{ 71 | member_since: 'member' 72 | }}) 73 | ## Delete Row 74 | db.comments.deleteOne({name: 'Harry'}) 75 | ## Less than/Greater than/ Less than or Eq/Greater than or Eq 76 | db.comments.find({member_since: {$lt: 90}}) 77 | db.comments.find({member_since: {$lte: 90}}) 78 | db.comments.find({member_since: {$gt: 90}}) 79 | db.comments.find({member_since: {$gte: 90}}) 80 | 81 | ## Clear mongodb compass terminal 82 | cls 83 | 84 | -------------------------------------------------------------------------------- /MongoDb-Commands/mongodbAtlas_mongodbCompass_postman.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/arhamansari11/Backend-Developement/f0765184454f09164178677f8fb0c52ef40c64b4/MongoDb-Commands/mongodbAtlas_mongodbCompass_postman.jpg -------------------------------------------------------------------------------- /MongoDb/.gitignore: -------------------------------------------------------------------------------- 1 | node_modules 2 | .env -------------------------------------------------------------------------------- /MongoDb/README.md: -------------------------------------------------------------------------------- 1 | ## Chapter 6 - MongoDB - Server / Mongo Shell (CLI) / Mongo Atlas 2 | 3 | ### [[ Reading Material]] 4 | 5 | MongoDB is **NoSQL** database which has a JSON like (BSON data) data storage. 6 | 7 | ## Setting up Database Server and Connecting with Mongo Shell 8 | 9 | After installing MongoDB community server package on your system - you will have to start the database server using command : 10 | 11 | ```bash 12 | mongod 13 | ``` 14 | 15 | This will start MongoDB server on default port 27017. You might have to create a directory for storage in MongoDB - if server asks for storage directory 16 | 17 | Once server is started - you can use `mongo` client to connect to local server 18 | 19 | ```bash 20 | mongo 21 | ``` 22 | 23 | Now you can use several commands to work with database: 24 | 25 | ``` 26 | show dbs 27 | ``` 28 | 29 | This will list all the database in your system 30 | 31 | ``` 32 | use 33 | ``` 34 | 35 | This will command will let you switch to a particular 36 | 37 | ## Understanding MongoDB structure 38 | 39 | 1. Hostname 40 | 2. Database 41 | 3. Collection 42 | 4. Document 43 | 44 | Hostname is Database server address - like `localhost` or `db.xy.com`. In mongoDB hostname generally uses mongodb protocol to connect. 45 | So URLs are generally are of shape : `mongodb://localhost:27017` 46 | 47 | Database are topmost storage level of your data - mostly each application has 1 database - however complex application might have more than 1 databases. Database is something like `university database` 48 | 49 | There can be many collections inside a database - collection is a group of documents of similar kind - `students`, `teachers`, `courses` etc 50 | 51 | Finally document is basic entity of storage in Mongod, it looks very similar to an object in JSON. (However it is BSON) 52 | 53 | 54 | ## MONGO CLI 55 | 56 | 57 | Mongo DB community server comes with in-bulit Mongo CLI which can act as a terminal based client. You can use the CRUD functionality from here 58 | 59 | Read the commands [here](https://docs.mongodb.com/manual/reference/mongo-shell/) 60 | 61 | #### Assignment 1 62 | 63 | * Try these commands given in Mongo CLI reference docs. 64 | 1. Show database 65 | 2. Use database 66 | 3. Show collection 67 | 4. Create Query (insertOne, insertMany) 68 | 5. Read Query (find, findOne) 69 | 6. Update Query (updateOne) 70 | 7. Delete Query (deleteOne, deleteMany) 71 | 8. Delete database (drop) 72 | 73 | #### Assignment 2 74 | 75 | #### Mongodump and Mongorestore 76 | 77 | These utilities comes with community server and can be found in CMD/terminal. They are not the part of Mongo CLI client. 78 | 79 | 1. Mongodump command is used to take backup of complete database or some collections 80 | 81 | ```bash 82 | mongodump --db accounts 83 | ``` 84 | Above command takes backup of database `accounts` and stores into a directory named `dump` 85 | 86 | 2. Mongorestore command is used to restore database 87 | 88 | ```bash 89 | 90 | mongorestore --db accounts dump/accounts 91 | 92 | ``` 93 | 94 | Above command restore your database `accounts` from backup directory `dump` 95 | 96 | 97 | 98 | **Task** : Use these commands on terminal/CMD (not inside mongo client) 99 | 100 | 1. Take a backup of database you created in assignment 1. 101 | 102 | 2. Restore the backup of database from `dump` directory. 103 | 104 | 105 | 106 | 107 | #### Using MONGODB NODE.JS DRIVER [ OPTIONAL READING - as we will not use Mongo Driver ] 108 | 109 | To install MONGODB NODE.JS DRIVER use this command 110 | 111 | ```javascript 112 | npm install mongodb 113 | ``` 114 | 115 | You can setup database in Node server using following commands : 116 | 117 | ```javascript 118 | 119 | const MongoClient = require('mongodb').MongoClient; 120 | const assert = require('assert'); 121 | 122 | // Connection URL 123 | const url = 'mongodb://localhost:27017'; 124 | 125 | // Database Name 126 | const dbName = 'myproject'; 127 | 128 | // Use connect method to connect to the Server 129 | MongoClient.connect(url, function(err, client) { 130 | assert.equal(null, err); 131 | console.log("Connected correctly to server"); 132 | 133 | const db = client.db(dbName); 134 | 135 | }); 136 | ``` 137 | 138 | Now this `db` handle can be used to perform any CRUD operation using MongoDB NodeJS driver. 139 | 140 | #### CRUD Functions links 141 | 142 | 1. Create - [Shell Version](https://docs.mongodb.com/manual/crud/#create-operations) / [Node Version](http://mongodb.github.io/node-mongodb-native/3.0/tutorials/crud#insert-documents) 143 | 2. Read - [Shell Version](https://docs.mongodb.com/manual/crud/#read-operations) / [Node Version](http://mongodb.github.io/node-mongodb-native/3.0/tutorials/crud#findoneandupdate-findoneanddelete-and-findoneandreplace) 144 | 3. Update - [Shell Version](https://docs.mongodb.com/manual/crud/#update-operations) / [Node Version](http://mongodb.github.io/node-mongodb-native/3.0/tutorials/crud#updating-documents) 145 | 4. Delete - [Shell Version](https://docs.mongodb.com/manual/crud/#delete-operations) / [Node Version](http://mongodb.github.io/node-mongodb-native/3.0/tutorials/crud#removing-documents) 146 | 147 | 148 | 149 | 150 | ### [[ Chapter Notes ]] 151 | 152 | **Mongo Server** 153 | - You can install **MongoDB community server** for your system and set the **Path** to `bin` folder 154 | - You can choose your own database path while starting the **mongod** server 155 | ``` 156 | mongod --dbpath 157 | ``` 158 | 159 | **Mongo Compass** : UI Client to see mongo server (local or remote) 160 | 161 | **Mongo Shell** : Command-line based mongo client for checking mongo database. 162 | 163 | Some Mongo Commands: 164 | 165 | ### Top Level commands : 166 | (run from anywhere inside the shell) 167 | - show dbs; 168 | - use < database-name > - to choose a database and go inside its prompt 169 | 170 | ### Database CRUD commands : 171 | (run only from inside a database) 172 | 173 | #### CREATE COMMANDS 174 | - db.< collectionName >.insertOne( *newDocument* ) 175 | - db.< collectionName >.insertMany( *documentArray* ) 176 | 177 | #### READ COMMANDS 178 | - db.< collectionName >.**find**( *filterObject* ) - to read all docs 179 | - db.< collectionName >.**findOne**( *filterObject* ) - to read one document 180 | - db.< collectionName >.**countDocuments**( *filterObject* ) - shows total number of documents. 181 | 182 | **filter** Object : *{ fieldName : {operator: value}}* 183 | fieldName : database fields name 184 | **operator** : $eq = equal , $gt= greater than, $lt : less than, $gte = greater than equal, $and and $or operator 185 | **value** : what value we are comparing with operator. 186 | 187 | e.g { age : {$gt:5}}. - **age** is **greater than** value **5** 188 | 189 | **Cursor functions :** 190 | These are applied to find() query . 191 | - **sort**( {fieldName: 1}) : 1 for ascending -1 for descending 192 | - **limit**( x ) : only gives x documents 193 | 194 | #### UPDATE COMMANDS 195 | 196 | - db.< collectionName >.**updateOne**( *filterObject*, *updateObject*, options ) 197 | - update Objects = *{ $set : {field: value}}* 198 | - options : *{upsert: true}* 199 | 200 | **Upsert** : Update + Insert, when we want a new info to create a new obejcts if no existing object matches filter queries. 201 | 202 | - db.< collectionName >.**replaceOne**( *filterObject*, *updateObject* ) 203 | Overwrites other fields also which are not in updateObject. 204 | 205 | #### DELETE COMMANDS 206 | 207 | - db.< collectionName >.**deleteOne**( *filterObject* ) 208 | 209 | 210 | **Projection** 211 | - Only return selected fields while returning result documents. 212 | - db.< collectionName >.find( *filterObject*, projectionObject ) 213 | e.g. {name:1, age:1, id:0} - only show **name** and **age** and don't show **id** 214 | 215 | **MONGO ATLAS CLOUD SETUP** : Check the video in tutorial 216 | 217 | ** Enviroment Variable** : To use environment variable we can use a npm package called **dotenv** which will create new **process.env** variables. 218 | - Install `dotenv` using `npm install dotenv` 219 | - just have use `.env` file in your root directory 220 | - and call `require('dotenv').config()` -------------------------------------------------------------------------------- /MongoDb/controller/product.js: -------------------------------------------------------------------------------- 1 | const fs = require('fs') 2 | const jsondata = JSON.parse(fs.readFileSync('./data.json', 'utf-8')); 3 | const product = jsondata.products; 4 | 5 | exports.createdata = (req, res) => { 6 | console.log(req.body); 7 | product.push(req.body); 8 | res.json(req.body); 9 | } 10 | 11 | exports.getAlldata = (req, res) => { 12 | res.json(product); 13 | console.log("GET API DONE"); 14 | } 15 | 16 | 17 | exports.getdatabyid = (req, res) => { 18 | const id = +req.params.id; 19 | const newpd = product.find(p => p.id === id) 20 | console.log(newpd); 21 | res.json(newpd); 22 | } 23 | exports.replacedata = (req, res) => { 24 | const id = +req.params.id; 25 | const newpdIndex = product.findIndex(p => p.id === id) 26 | product.splice(newpdIndex, 1, { ...req.body, id: id }) 27 | console.log(newpdIndex); 28 | res.status(202).json(); 29 | } 30 | 31 | 32 | exports.updatedata = (req, res) => { 33 | const id = +req.params.id; 34 | const newpdIndex = product.findIndex(p => p.id === id) 35 | const patchdata = product[newpdIndex] 36 | product.splice(newpdIndex, 1, { ...patchdata, ...req.body }) 37 | console.log(newpdIndex); 38 | res.status(202).json(); 39 | } 40 | 41 | exports.deletedata = (req, res) => { 42 | const id = +req.params.id; 43 | const newpdIndex = product.findIndex(p => p.id === id) 44 | const patchdata = product[newpdIndex] 45 | product.splice(newpdIndex, 1) 46 | console.log(newpdIndex); 47 | res.status(202).json(); 48 | } -------------------------------------------------------------------------------- /MongoDb/data.json: -------------------------------------------------------------------------------- 1 | { 2 | "products": [ 3 | { 4 | "id": 1, 5 | "title": "iPhone 9", 6 | "description": "An apple mobile which is nothing like apple", 7 | "price": 549, 8 | "discountPercentage": 12.96, 9 | "rating": 4.69, 10 | "stock": 94, 11 | "brand": "Apple", 12 | "category": "smartphones", 13 | "thumbnail": "https://i.dummyjson.com/data/products/1/thumbnail.jpg", 14 | "images": [ 15 | "https://i.dummyjson.com/data/products/1/1.jpg", 16 | "https://i.dummyjson.com/data/products/1/2.jpg", 17 | "https://i.dummyjson.com/data/products/1/3.jpg", 18 | "https://i.dummyjson.com/data/products/1/4.jpg", 19 | "https://i.dummyjson.com/data/products/1/thumbnail.jpg" 20 | ] 21 | }, 22 | { 23 | "id": 2, 24 | "title": "iPhone X", 25 | "description": "SIM-Free, Model A19211 6.5-inch Super Retina HD display with OLED technology A12 Bionic chip with ...", 26 | "price": 899, 27 | "discountPercentage": 17.94, 28 | "rating": 4.44, 29 | "stock": 34, 30 | "brand": "Apple", 31 | "category": "smartphones", 32 | "thumbnail": "https://i.dummyjson.com/data/products/2/thumbnail.jpg", 33 | "images": [ 34 | "https://i.dummyjson.com/data/products/2/1.jpg", 35 | "https://i.dummyjson.com/data/products/2/2.jpg", 36 | "https://i.dummyjson.com/data/products/2/3.jpg", 37 | "https://i.dummyjson.com/data/products/2/thumbnail.jpg" 38 | ] 39 | }, 40 | { 41 | "id": 3, 42 | "title": "Samsung Universe 9", 43 | "description": "Samsung's new variant which goes beyond Galaxy to the Universe", 44 | "price": 1249, 45 | "discountPercentage": 15.46, 46 | "rating": 4.09, 47 | "stock": 36, 48 | "brand": "Samsung", 49 | "category": "smartphones", 50 | "thumbnail": "https://i.dummyjson.com/data/products/3/thumbnail.jpg", 51 | "images": ["https://i.dummyjson.com/data/products/3/1.jpg"] 52 | }, 53 | { 54 | "id": 4, 55 | "title": "OPPOF19", 56 | "description": "OPPO F19 is officially announced on April 2021.", 57 | "price": 280, 58 | "discountPercentage": 17.91, 59 | "rating": 4.3, 60 | "stock": 123, 61 | "brand": "OPPO", 62 | "category": "smartphones", 63 | "thumbnail": "https://i.dummyjson.com/data/products/4/thumbnail.jpg", 64 | "images": [ 65 | "https://i.dummyjson.com/data/products/4/1.jpg", 66 | "https://i.dummyjson.com/data/products/4/2.jpg", 67 | "https://i.dummyjson.com/data/products/4/3.jpg", 68 | "https://i.dummyjson.com/data/products/4/4.jpg", 69 | "https://i.dummyjson.com/data/products/4/thumbnail.jpg" 70 | ] 71 | }, 72 | { 73 | "id": 5, 74 | "title": "Huawei P30", 75 | "description": "Huawei’s re-badged P30 Pro New Edition was officially unveiled yesterday in Germany and now the device has made its way to the UK.", 76 | "price": 499, 77 | "discountPercentage": 10.58, 78 | "rating": 4.09, 79 | "stock": 32, 80 | "brand": "Huawei", 81 | "category": "smartphones", 82 | "thumbnail": "https://i.dummyjson.com/data/products/5/thumbnail.jpg", 83 | "images": [ 84 | "https://i.dummyjson.com/data/products/5/1.jpg", 85 | "https://i.dummyjson.com/data/products/5/2.jpg", 86 | "https://i.dummyjson.com/data/products/5/3.jpg" 87 | ] 88 | }, 89 | { 90 | "id": 6, 91 | "title": "MacBook Pro", 92 | "description": "MacBook Pro 2021 with mini-LED display may launch between September, November", 93 | "price": 1749, 94 | "discountPercentage": 11.02, 95 | "rating": 4.57, 96 | "stock": 83, 97 | "brand": "Apple", 98 | "category": "laptops", 99 | "thumbnail": "https://i.dummyjson.com/data/products/6/thumbnail.png", 100 | "images": [ 101 | "https://i.dummyjson.com/data/products/6/1.png", 102 | "https://i.dummyjson.com/data/products/6/2.jpg", 103 | "https://i.dummyjson.com/data/products/6/3.png", 104 | "https://i.dummyjson.com/data/products/6/4.jpg" 105 | ] 106 | }, 107 | { 108 | "id": 7, 109 | "title": "Samsung Galaxy Book", 110 | "description": "Samsung Galaxy Book S (2020) Laptop With Intel Lakefield Chip, 8GB of RAM Launched", 111 | "price": 1499, 112 | "discountPercentage": 4.15, 113 | "rating": 4.25, 114 | "stock": 50, 115 | "brand": "Samsung", 116 | "category": "laptops", 117 | "thumbnail": "https://i.dummyjson.com/data/products/7/thumbnail.jpg", 118 | "images": [ 119 | "https://i.dummyjson.com/data/products/7/1.jpg", 120 | "https://i.dummyjson.com/data/products/7/2.jpg", 121 | "https://i.dummyjson.com/data/products/7/3.jpg", 122 | "https://i.dummyjson.com/data/products/7/thumbnail.jpg" 123 | ] 124 | }, 125 | { 126 | "id": 8, 127 | "title": "Microsoft Surface Laptop 4", 128 | "description": "Style and speed. Stand out on HD video calls backed by Studio Mics. Capture ideas on the vibrant touchscreen.", 129 | "price": 1499, 130 | "discountPercentage": 10.23, 131 | "rating": 4.43, 132 | "stock": 68, 133 | "brand": "Microsoft Surface", 134 | "category": "laptops", 135 | "thumbnail": "https://i.dummyjson.com/data/products/8/thumbnail.jpg", 136 | "images": [ 137 | "https://i.dummyjson.com/data/products/8/1.jpg", 138 | "https://i.dummyjson.com/data/products/8/2.jpg", 139 | "https://i.dummyjson.com/data/products/8/3.jpg", 140 | "https://i.dummyjson.com/data/products/8/4.jpg", 141 | "https://i.dummyjson.com/data/products/8/thumbnail.jpg" 142 | ] 143 | }, 144 | { 145 | "id": 9, 146 | "title": "Infinix INBOOK", 147 | "description": "Infinix Inbook X1 Ci3 10th 8GB 256GB 14 Win10 Grey – 1 Year Warranty", 148 | "price": 1099, 149 | "discountPercentage": 11.83, 150 | "rating": 4.54, 151 | "stock": 96, 152 | "brand": "Infinix", 153 | "category": "laptops", 154 | "thumbnail": "https://i.dummyjson.com/data/products/9/thumbnail.jpg", 155 | "images": [ 156 | "https://i.dummyjson.com/data/products/9/1.jpg", 157 | "https://i.dummyjson.com/data/products/9/2.png", 158 | "https://i.dummyjson.com/data/products/9/3.png", 159 | "https://i.dummyjson.com/data/products/9/4.jpg", 160 | "https://i.dummyjson.com/data/products/9/thumbnail.jpg" 161 | ] 162 | }, 163 | { 164 | "id": 10, 165 | "title": "HP Pavilion 15-DK1056WM", 166 | "description": "HP Pavilion 15-DK1056WM Gaming Laptop 10th Gen Core i5, 8GB, 256GB SSD, GTX 1650 4GB, Windows 10", 167 | "price": 1099, 168 | "discountPercentage": 6.18, 169 | "rating": 4.43, 170 | "stock": 89, 171 | "brand": "HP Pavilion", 172 | "category": "laptops", 173 | "thumbnail": "https://i.dummyjson.com/data/products/10/thumbnail.jpeg", 174 | "images": [ 175 | "https://i.dummyjson.com/data/products/10/1.jpg", 176 | "https://i.dummyjson.com/data/products/10/2.jpg", 177 | "https://i.dummyjson.com/data/products/10/3.jpg", 178 | "https://i.dummyjson.com/data/products/10/thumbnail.jpeg" 179 | ] 180 | }, 181 | { 182 | "id": 11, 183 | "title": "perfume Oil", 184 | "description": "Mega Discount, Impression of Acqua Di Gio by GiorgioArmani concentrated attar perfume Oil", 185 | "price": 13, 186 | "discountPercentage": 8.4, 187 | "rating": 4.26, 188 | "stock": 65, 189 | "brand": "Impression of Acqua Di Gio", 190 | "category": "fragrances", 191 | "thumbnail": "https://i.dummyjson.com/data/products/11/thumbnail.jpg", 192 | "images": [ 193 | "https://i.dummyjson.com/data/products/11/1.jpg", 194 | "https://i.dummyjson.com/data/products/11/2.jpg", 195 | "https://i.dummyjson.com/data/products/11/3.jpg", 196 | "https://i.dummyjson.com/data/products/11/thumbnail.jpg" 197 | ] 198 | }, 199 | { 200 | "id": 12, 201 | "title": "Brown Perfume", 202 | "description": "Royal_Mirage Sport Brown Perfume for Men & Women - 120ml", 203 | "price": 40, 204 | "discountPercentage": 15.66, 205 | "rating": 4, 206 | "stock": 52, 207 | "brand": "Royal_Mirage", 208 | "category": "fragrances", 209 | "thumbnail": "https://i.dummyjson.com/data/products/12/thumbnail.jpg", 210 | "images": [ 211 | "https://i.dummyjson.com/data/products/12/1.jpg", 212 | "https://i.dummyjson.com/data/products/12/2.jpg", 213 | "https://i.dummyjson.com/data/products/12/3.png", 214 | "https://i.dummyjson.com/data/products/12/4.jpg", 215 | "https://i.dummyjson.com/data/products/12/thumbnail.jpg" 216 | ] 217 | }, 218 | { 219 | "id": 13, 220 | "title": "Fog Scent Xpressio Perfume", 221 | "description": "Product details of Best Fog Scent Xpressio Perfume 100ml For Men cool long lasting perfumes for Men", 222 | "price": 13, 223 | "discountPercentage": 8.14, 224 | "rating": 4.59, 225 | "stock": 61, 226 | "brand": "Fog Scent Xpressio", 227 | "category": "fragrances", 228 | "thumbnail": "https://i.dummyjson.com/data/products/13/thumbnail.webp", 229 | "images": [ 230 | "https://i.dummyjson.com/data/products/13/1.jpg", 231 | "https://i.dummyjson.com/data/products/13/2.png", 232 | "https://i.dummyjson.com/data/products/13/3.jpg", 233 | "https://i.dummyjson.com/data/products/13/4.jpg", 234 | "https://i.dummyjson.com/data/products/13/thumbnail.webp" 235 | ] 236 | }, 237 | { 238 | "id": 14, 239 | "title": "Non-Alcoholic Concentrated Perfume Oil", 240 | "description": "Original Al Munakh® by Mahal Al Musk | Our Impression of Climate | 6ml Non-Alcoholic Concentrated Perfume Oil", 241 | "price": 120, 242 | "discountPercentage": 15.6, 243 | "rating": 4.21, 244 | "stock": 114, 245 | "brand": "Al Munakh", 246 | "category": "fragrances", 247 | "thumbnail": "https://i.dummyjson.com/data/products/14/thumbnail.jpg", 248 | "images": [ 249 | "https://i.dummyjson.com/data/products/14/1.jpg", 250 | "https://i.dummyjson.com/data/products/14/2.jpg", 251 | "https://i.dummyjson.com/data/products/14/3.jpg", 252 | "https://i.dummyjson.com/data/products/14/thumbnail.jpg" 253 | ] 254 | }, 255 | { 256 | "id": 15, 257 | "title": "Eau De Perfume Spray", 258 | "description": "Genuine Al-Rehab spray perfume from UAE/Saudi Arabia/Yemen High Quality", 259 | "price": 30, 260 | "discountPercentage": 10.99, 261 | "rating": 4.7, 262 | "stock": 105, 263 | "brand": "Lord - Al-Rehab", 264 | "category": "fragrances", 265 | "thumbnail": "https://i.dummyjson.com/data/products/15/thumbnail.jpg", 266 | "images": [ 267 | "https://i.dummyjson.com/data/products/15/1.jpg", 268 | "https://i.dummyjson.com/data/products/15/2.jpg", 269 | "https://i.dummyjson.com/data/products/15/3.jpg", 270 | "https://i.dummyjson.com/data/products/15/4.jpg", 271 | "https://i.dummyjson.com/data/products/15/thumbnail.jpg" 272 | ] 273 | }, 274 | { 275 | "id": 16, 276 | "title": "Hyaluronic Acid Serum", 277 | "description": "L'Oréal Paris introduces Hyaluron Expert Replumping Serum formulated with 1.5% Hyaluronic Acid", 278 | "price": 19, 279 | "discountPercentage": 13.31, 280 | "rating": 4.83, 281 | "stock": 110, 282 | "brand": "L'Oreal Paris", 283 | "category": "skincare", 284 | "thumbnail": "https://i.dummyjson.com/data/products/16/thumbnail.jpg", 285 | "images": [ 286 | "https://i.dummyjson.com/data/products/16/1.png", 287 | "https://i.dummyjson.com/data/products/16/2.webp", 288 | "https://i.dummyjson.com/data/products/16/3.jpg", 289 | "https://i.dummyjson.com/data/products/16/4.jpg", 290 | "https://i.dummyjson.com/data/products/16/thumbnail.jpg" 291 | ] 292 | }, 293 | { 294 | "id": 17, 295 | "title": "Tree Oil 30ml", 296 | "description": "Tea tree oil contains a number of compounds, including terpinen-4-ol, that have been shown to kill certain bacteria,", 297 | "price": 12, 298 | "discountPercentage": 4.09, 299 | "rating": 4.52, 300 | "stock": 78, 301 | "brand": "Hemani Tea", 302 | "category": "skincare", 303 | "thumbnail": "https://i.dummyjson.com/data/products/17/thumbnail.jpg", 304 | "images": [ 305 | "https://i.dummyjson.com/data/products/17/1.jpg", 306 | "https://i.dummyjson.com/data/products/17/2.jpg", 307 | "https://i.dummyjson.com/data/products/17/3.jpg", 308 | "https://i.dummyjson.com/data/products/17/thumbnail.jpg" 309 | ] 310 | }, 311 | { 312 | "id": 18, 313 | "title": "Oil Free Moisturizer 100ml", 314 | "description": "Dermive Oil Free Moisturizer with SPF 20 is specifically formulated with ceramides, hyaluronic acid & sunscreen.", 315 | "price": 40, 316 | "discountPercentage": 13.1, 317 | "rating": 4.56, 318 | "stock": 88, 319 | "brand": "Dermive", 320 | "category": "skincare", 321 | "thumbnail": "https://i.dummyjson.com/data/products/18/thumbnail.jpg", 322 | "images": [ 323 | "https://i.dummyjson.com/data/products/18/1.jpg", 324 | "https://i.dummyjson.com/data/products/18/2.jpg", 325 | "https://i.dummyjson.com/data/products/18/3.jpg", 326 | "https://i.dummyjson.com/data/products/18/4.jpg", 327 | "https://i.dummyjson.com/data/products/18/thumbnail.jpg" 328 | ] 329 | }, 330 | { 331 | "id": 19, 332 | "title": "Skin Beauty Serum.", 333 | "description": "Product name: rorec collagen hyaluronic acid white face serum riceNet weight: 15 m", 334 | "price": 46, 335 | "discountPercentage": 10.68, 336 | "rating": 4.42, 337 | "stock": 54, 338 | "brand": "ROREC White Rice", 339 | "category": "skincare", 340 | "thumbnail": "https://i.dummyjson.com/data/products/19/thumbnail.jpg", 341 | "images": [ 342 | "https://i.dummyjson.com/data/products/19/1.jpg", 343 | "https://i.dummyjson.com/data/products/19/2.jpg", 344 | "https://i.dummyjson.com/data/products/19/3.png", 345 | "https://i.dummyjson.com/data/products/19/thumbnail.jpg" 346 | ] 347 | }, 348 | { 349 | "id": 20, 350 | "title": "Freckle Treatment Cream- 15gm", 351 | "description": "Fair & Clear is Pakistan's only pure Freckle cream which helpsfade Freckles, Darkspots and pigments. Mercury level is 0%, so there are no side effects.", 352 | "price": 70, 353 | "discountPercentage": 16.99, 354 | "rating": 4.06, 355 | "stock": 140, 356 | "brand": "Fair & Clear", 357 | "category": "skincare", 358 | "thumbnail": "https://i.dummyjson.com/data/products/20/thumbnail.jpg", 359 | "images": [ 360 | "https://i.dummyjson.com/data/products/20/1.jpg", 361 | "https://i.dummyjson.com/data/products/20/2.jpg", 362 | "https://i.dummyjson.com/data/products/20/3.jpg", 363 | "https://i.dummyjson.com/data/products/20/4.jpg", 364 | "https://i.dummyjson.com/data/products/20/thumbnail.jpg" 365 | ] 366 | }, 367 | { 368 | "id": 21, 369 | "title": "- Daal Masoor 500 grams", 370 | "description": "Fine quality Branded Product Keep in a cool and dry place", 371 | "price": 20, 372 | "discountPercentage": 4.81, 373 | "rating": 4.44, 374 | "stock": 133, 375 | "brand": "Saaf & Khaas", 376 | "category": "groceries", 377 | "thumbnail": "https://i.dummyjson.com/data/products/21/thumbnail.png", 378 | "images": [ 379 | "https://i.dummyjson.com/data/products/21/1.png", 380 | "https://i.dummyjson.com/data/products/21/2.jpg", 381 | "https://i.dummyjson.com/data/products/21/3.jpg" 382 | ] 383 | }, 384 | { 385 | "id": 22, 386 | "title": "Elbow Macaroni - 400 gm", 387 | "description": "Product details of Bake Parlor Big Elbow Macaroni - 400 gm", 388 | "price": 14, 389 | "discountPercentage": 15.58, 390 | "rating": 4.57, 391 | "stock": 146, 392 | "brand": "Bake Parlor Big", 393 | "category": "groceries", 394 | "thumbnail": "https://i.dummyjson.com/data/products/22/thumbnail.jpg", 395 | "images": [ 396 | "https://i.dummyjson.com/data/products/22/1.jpg", 397 | "https://i.dummyjson.com/data/products/22/2.jpg", 398 | "https://i.dummyjson.com/data/products/22/3.jpg" 399 | ] 400 | }, 401 | { 402 | "id": 23, 403 | "title": "Orange Essence Food Flavou", 404 | "description": "Specifications of Orange Essence Food Flavour For Cakes and Baking Food Item", 405 | "price": 14, 406 | "discountPercentage": 8.04, 407 | "rating": 4.85, 408 | "stock": 26, 409 | "brand": "Baking Food Items", 410 | "category": "groceries", 411 | "thumbnail": "https://i.dummyjson.com/data/products/23/thumbnail.jpg", 412 | "images": [ 413 | "https://i.dummyjson.com/data/products/23/1.jpg", 414 | "https://i.dummyjson.com/data/products/23/2.jpg", 415 | "https://i.dummyjson.com/data/products/23/3.jpg", 416 | "https://i.dummyjson.com/data/products/23/4.jpg", 417 | "https://i.dummyjson.com/data/products/23/thumbnail.jpg" 418 | ] 419 | }, 420 | { 421 | "id": 24, 422 | "title": "cereals muesli fruit nuts", 423 | "description": "original fauji cereal muesli 250gm box pack original fauji cereals muesli fruit nuts flakes breakfast cereal break fast faujicereals cerels cerel foji fouji", 424 | "price": 46, 425 | "discountPercentage": 16.8, 426 | "rating": 4.94, 427 | "stock": 113, 428 | "brand": "fauji", 429 | "category": "groceries", 430 | "thumbnail": "https://i.dummyjson.com/data/products/24/thumbnail.jpg", 431 | "images": [ 432 | "https://i.dummyjson.com/data/products/24/1.jpg", 433 | "https://i.dummyjson.com/data/products/24/2.jpg", 434 | "https://i.dummyjson.com/data/products/24/3.jpg", 435 | "https://i.dummyjson.com/data/products/24/4.jpg", 436 | "https://i.dummyjson.com/data/products/24/thumbnail.jpg" 437 | ] 438 | }, 439 | { 440 | "id": 25, 441 | "title": "Gulab Powder 50 Gram", 442 | "description": "Dry Rose Flower Powder Gulab Powder 50 Gram • Treats Wounds", 443 | "price": 70, 444 | "discountPercentage": 13.58, 445 | "rating": 4.87, 446 | "stock": 47, 447 | "brand": "Dry Rose", 448 | "category": "groceries", 449 | "thumbnail": "https://i.dummyjson.com/data/products/25/thumbnail.jpg", 450 | "images": [ 451 | "https://i.dummyjson.com/data/products/25/1.png", 452 | "https://i.dummyjson.com/data/products/25/2.jpg", 453 | "https://i.dummyjson.com/data/products/25/3.png", 454 | "https://i.dummyjson.com/data/products/25/4.jpg", 455 | "https://i.dummyjson.com/data/products/25/thumbnail.jpg" 456 | ] 457 | }, 458 | { 459 | "id": 26, 460 | "title": "Plant Hanger For Home", 461 | "description": "Boho Decor Plant Hanger For Home Wall Decoration Macrame Wall Hanging Shelf", 462 | "price": 41, 463 | "discountPercentage": 17.86, 464 | "rating": 4.08, 465 | "stock": 131, 466 | "brand": "Boho Decor", 467 | "category": "home-decoration", 468 | "thumbnail": "https://i.dummyjson.com/data/products/26/thumbnail.jpg", 469 | "images": [ 470 | "https://i.dummyjson.com/data/products/26/1.jpg", 471 | "https://i.dummyjson.com/data/products/26/2.jpg", 472 | "https://i.dummyjson.com/data/products/26/3.jpg", 473 | "https://i.dummyjson.com/data/products/26/4.jpg", 474 | "https://i.dummyjson.com/data/products/26/5.jpg", 475 | "https://i.dummyjson.com/data/products/26/thumbnail.jpg" 476 | ] 477 | }, 478 | { 479 | "id": 27, 480 | "title": "Flying Wooden Bird", 481 | "description": "Package Include 6 Birds with Adhesive Tape Shape: 3D Shaped Wooden Birds Material: Wooden MDF, Laminated 3.5mm", 482 | "price": 51, 483 | "discountPercentage": 15.58, 484 | "rating": 4.41, 485 | "stock": 17, 486 | "brand": "Flying Wooden", 487 | "category": "home-decoration", 488 | "thumbnail": "https://i.dummyjson.com/data/products/27/thumbnail.webp", 489 | "images": [ 490 | "https://i.dummyjson.com/data/products/27/1.jpg", 491 | "https://i.dummyjson.com/data/products/27/2.jpg", 492 | "https://i.dummyjson.com/data/products/27/3.jpg", 493 | "https://i.dummyjson.com/data/products/27/4.jpg", 494 | "https://i.dummyjson.com/data/products/27/thumbnail.webp" 495 | ] 496 | }, 497 | { 498 | "id": 28, 499 | "title": "3D Embellishment Art Lamp", 500 | "description": "3D led lamp sticker Wall sticker 3d wall art light on/off button cell operated (included)", 501 | "price": 20, 502 | "discountPercentage": 16.49, 503 | "rating": 4.82, 504 | "stock": 54, 505 | "brand": "LED Lights", 506 | "category": "home-decoration", 507 | "thumbnail": "https://i.dummyjson.com/data/products/28/thumbnail.jpg", 508 | "images": [ 509 | "https://i.dummyjson.com/data/products/28/1.jpg", 510 | "https://i.dummyjson.com/data/products/28/2.jpg", 511 | "https://i.dummyjson.com/data/products/28/3.png", 512 | "https://i.dummyjson.com/data/products/28/4.jpg", 513 | "https://i.dummyjson.com/data/products/28/thumbnail.jpg" 514 | ] 515 | }, 516 | { 517 | "id": 29, 518 | "title": "Handcraft Chinese style", 519 | "description": "Handcraft Chinese style art luxury palace hotel villa mansion home decor ceramic vase with brass fruit plate", 520 | "price": 60, 521 | "discountPercentage": 15.34, 522 | "rating": 4.44, 523 | "stock": 7, 524 | "brand": "luxury palace", 525 | "category": "home-decoration", 526 | "thumbnail": "https://i.dummyjson.com/data/products/29/thumbnail.webp", 527 | "images": [ 528 | "https://i.dummyjson.com/data/products/29/1.jpg", 529 | "https://i.dummyjson.com/data/products/29/2.jpg", 530 | "https://i.dummyjson.com/data/products/29/3.webp", 531 | "https://i.dummyjson.com/data/products/29/4.webp", 532 | "https://i.dummyjson.com/data/products/29/thumbnail.webp" 533 | ] 534 | }, 535 | { 536 | "id": 30, 537 | "title": "Key Holder", 538 | "description": "Attractive DesignMetallic materialFour key hooksReliable & DurablePremium Quality", 539 | "price": 30, 540 | "discountPercentage": 2.92, 541 | "rating": 4.92, 542 | "stock": 54, 543 | "brand": "Golden", 544 | "category": "home-decoration", 545 | "thumbnail": "https://i.dummyjson.com/data/products/30/thumbnail.jpg", 546 | "images": [ 547 | "https://i.dummyjson.com/data/products/30/1.jpg", 548 | "https://i.dummyjson.com/data/products/30/2.jpg", 549 | "https://i.dummyjson.com/data/products/30/3.jpg", 550 | "https://i.dummyjson.com/data/products/30/thumbnail.jpg" 551 | ] 552 | } 553 | ] 554 | } 555 | -------------------------------------------------------------------------------- /MongoDb/index.js: -------------------------------------------------------------------------------- 1 | require('dotenv').config() 2 | const express = require('express') 3 | const server = express() 4 | const productrouter = require('./routes/routes.js') 5 | 6 | // Body Parser Middlewear 7 | server.use(express.json()); 8 | server.use(express.static(process.env.PUBLIC_DIR)); 9 | server.use('/products', productrouter.routing) 10 | 11 | 12 | console.log('Password :',process.env.DB_PASSWORD) 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | server.listen(process.env.PORT, () => { 22 | console.log("Server Running on :",process.env.PORT); 23 | }) 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | -------------------------------------------------------------------------------- /MongoDb/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "node-class-02", 3 | "version": "1.0.0", 4 | "description": "", 5 | "main": "index.js", 6 | "scripts": { 7 | "start": "nodemon index.js", 8 | "test": "echo \"Error: no test specified\" && exit 1" 9 | }, 10 | "keywords": [], 11 | "author": "", 12 | "license": "ISC", 13 | "dependencies": { 14 | "dotenv": "^16.3.1", 15 | "express": "^4.18.2", 16 | "morgan": "^1.10.0" 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /MongoDb/routes/routes.js: -------------------------------------------------------------------------------- 1 | const express = require('express'); 2 | const controller = require('../controller/product.js') 3 | const router = express.Router(); 4 | 5 | 6 | 7 | router 8 | .post('/', controller.createdata) 9 | .get('/', controller.getAlldata) 10 | .get('/:id', controller.getdatabyid) 11 | .put('/:id', controller.replacedata) 12 | .patch('/:id', controller.updatedata) 13 | .delete('/:id', controller.deletedata) 14 | 15 | exports.routing = router; -------------------------------------------------------------------------------- /Mongoose/.gitignore: -------------------------------------------------------------------------------- 1 | node_modules 2 | .env -------------------------------------------------------------------------------- /Mongoose/README.md: -------------------------------------------------------------------------------- 1 | ## Chapter 7 - Mongoose and REST APIs 2 | 3 | ### [[ Reading Material ]] 4 | 5 | 6 | You can install mongoose using npm : 7 | 8 | ```bash 9 | npm install mongoose 10 | ``` 11 | 12 | After installing , you can import mongoose to your project : 13 | 14 | ```js 15 | const mongoose = require("mongoose"); 16 | ``` 17 | 18 | #### Connection to Database 19 | 20 | To connect mongoose to your database `test`, you have to use the following commands : 21 | 22 | ```js 23 | 24 | var mongoose = require('mongoose'); 25 | await mongoose.connect('mongodb://127.0.0.1:27017/test'); 26 | ``` 27 | 28 | Connection can also be stored in a variable to check whether it is connected properly or not. Also to disconnect database later on. You can read more details [Here](https://mongoosejs.com/docs/connections.html) 29 | 30 | #### Schema 31 | 32 | Schema is the specification according to which data object is created in Database. 33 | 34 | `taskSchema` which contains `title`, `status`, `date` fields. So every task object saved in database will have these 3 fields according to Schema given 35 | 36 | 37 | ```js 38 | 39 | const mongoose = require('mongoose'); 40 | const Schema = mongoose.Schema; 41 | 42 | const taskSchema = new Schema({ 43 | title: String, 44 | status: Boolean, 45 | date: { type: Date, default: Date.now } 46 | }); 47 | ``` 48 | 49 | Many types of data are allowed in Mongoose Schema. The common SchemaTypes are: 50 | 51 | * String 52 | * Number 53 | * Date 54 | * Boolean 55 | * Mixed 56 | * ObjectId 57 | * Array 58 | 59 | You can put a lot of conditions inside the Schema object : 60 | 61 | ```js 62 | 63 | age: { type: Number, default:18, min: 18, max: 65, required :true } 64 | // default value of Number is 18 and should be between 18-65, and can't be null or empty 65 | 66 | ``` 67 | 68 | Detailed information on SchemaTypes is [Here](https://mongoosejs.com/docs/schematypes.html) 69 | 70 | #### Model 71 | 72 | Model are similar to classes, they create a Class from Schema. These classes(i.e Models) can be used to create each new database object. 73 | 74 | 75 | ```js 76 | const mongoose = require('mongoose'); 77 | const { Schema } = mongoose; 78 | 79 | const taskSchema = new Schema({ 80 | title: String, 81 | status: Boolean, 82 | date: { type: Date, default: Date.now }, 83 | }); 84 | 85 | const Task = mongoose.model('Task', taskSchema); //Task Model to create new database objects for `tasks` Collection 86 | 87 | 88 | ``` 89 | 90 | #### Task 1 91 | 92 | Connect mongoose to a database named `todolist` if you don't have a database with this name. Mongoose will create it after you perform any insert operation. 93 | 94 | Creata a Schema named `taskSchema` and model named `Task` as shown above. 95 | 96 | 97 | ### CRUD in Mongoose 98 | 99 | ### Create - new objects 100 | 101 | To Create new obejct in database we can use `new` keyword and create an object from Model. We can use `save()` function to save the object in database. Unless, you call save function - the object remains in memory. If your collection not yet created in MongoDB, it will created with name of Model pluralized (e.g Task will make a collection named `tasks`) 102 | 103 | 104 | ```js 105 | 106 | server.post("/task",function(req,res){ 107 | let task = new Task(); 108 | 109 | task.title = "shopping"; 110 | task.status = true; 111 | task.date = new Date(); 112 | 113 | task.save(); 114 | }) 115 | 116 | ``` 117 | 118 | #### Task 2 119 | 120 | You have to create an API Endpoint to type `POST` named `/task`. It will create a new task item in database whenever called properly. All 3 fields `title`, `status`, `date` must be mandatory (`required`). If someone is not passing all fields properly, no database entry should be created. 121 | 122 | ```js 123 | //request body : 124 | 125 | { 126 | "title" : "task1", 127 | "status" : true, 128 | "date" :'2010-05-30" 129 | 130 | } 131 | 132 | // response body should return the newly created object. 133 | 134 | res.json(task); 135 | 136 | ``` 137 | 138 | Check using Mongo Compass/or Mongo Shell that new record in database is created. Also check name of collection. Is is `tasks` ? 139 | 140 | 141 | ### Read objects 142 | 143 | To read new obejcts from database, one can use `find` query or similar queries. `find` queries also contain some conditions which can restrict what kind of data objects you want to read from database. 144 | 145 | 146 | ```js 147 | 148 | server.get("/task/:name",function(req,res){ 149 | Task.findOne({name:req.params.name},function(err,doc){ 150 | console.log(doc) // this will contain db object 151 | }) 152 | }) 153 | 154 | 155 | server.get("/tasks",function(req,res){ 156 | Task.find({},function(err,docs){ 157 | console.log(docs) // this is an array which contains all task objects 158 | }) 159 | }) 160 | 161 | 162 | ``` 163 | #### Task 3 164 | 165 | You have to create an API Endpoint to type `GET` named `/tasks`. It will return all task available in collection `tasks`. 166 | 167 | ```js 168 | //request is GET so no data in body : 169 | 170 | 171 | // response body should return the all db objects of collection tasks. 172 | 173 | res.json(tasks); 174 | 175 | ``` 176 | 177 | Check Mongo Compass/or Mongo Shell - if all records are returned in response. How you will change this API to make it return only one database record in which `title` is matched with `title` sent in request `query`. 178 | 179 | 180 | 181 | ### Update - existing objects 182 | 183 | To Update an existing object in database we need to first find an object from database and then update in database. This might be considered as a combination of `find` and `save` methods. 184 | 185 | 186 | There are generally 2 cases in update : 187 | 188 | 1. Updating all values and overwriting the object properties completely. 189 | 2. Updating only few values by setting their new values. 190 | 191 | 192 | First scenario is covered using this query. Here you are overwriting all properties and resulting object will only have `name` property. 193 | 194 | ```js 195 | 196 | server.put("/task/:name",function(req,res){ 197 | Task.findOneAndReplace({name:req.params.name},{name:'YouStart'},{new:true},function(err,doc){ 198 | console.log(doc) // this will contain new db object 199 | }) 200 | }) 201 | 202 | ``` 203 | 204 | Second scenario is covered using this query. Here you are only changing value of `name` property in existing object without changing other values in Object. 205 | 206 | ```js 207 | 208 | server.put("/task/:name",function(req,res){ 209 | Task.findOneAndUpdate({name:req.params.name},{name:'YouStart'},,{new:true},function(err,doc){ 210 | console.log(doc) // this will contain db object 211 | }) 212 | }) 213 | 214 | ``` 215 | 216 | #### Task 4 217 | 218 | You have to create an API Endpoint to type `PUT` named `/task/:id`. It will update existing task item in database which has ObjectId set to `id` you have passed. 219 | 220 | ```js 221 | //request params will have id in URL path : 222 | 223 | { 224 | "title" : "task-changed", 225 | } 226 | 227 | // response body should return the newly updated object. 228 | 229 | res.json(task); 230 | 231 | ``` 232 | 233 | Check using Mongo Compass/or Mongo Shell that only `title` of record in database is changed. All other properties remain the same. 234 | 235 | 236 | 237 | ### Delete - existing objects 238 | 239 | To Delete existing object from database we need to first find an object from database and then delete. This might be considered as a combination of `find` and `delete` methods. 240 | 241 | 242 | ```js 243 | 244 | server.delete("/task/:name",function(req,res){ 245 | Task.findOneAndDelete({name:req.params.name},function(err,doc){ 246 | console.log(doc) // this will contain deleted object object 247 | }) 248 | }) 249 | 250 | ``` 251 | 252 | #### Task 5 253 | 254 | You have to create an API Endpoint to type `DELETE` named `/task/:id`. It will delete existing task item in database which has ObjectId set to `id` you have passed. 255 | 256 | ```js 257 | //request params will have id in URL path : 258 | 259 | // response body should return the deleted object. 260 | 261 | res.json(task); 262 | 263 | ``` 264 | 265 | Check using Mongo Compass/or Mongo Shell that the record is deleted or not. 266 | 267 | 268 | 269 | 270 | ### [[ Chapter Notes ]] 271 | 272 | - install mongoose 273 | `npm install mongoose` 274 | - Mongoose connection code 275 | ```javascript 276 | main().catch(err => console.log(err)); 277 | 278 | async function main() { 279 | await mongoose.connect('mongodb://127.0.0.1:27017/test'); 280 | 281 | // use `await mongoose.connect('mongodb://user:password@127.0.0.1:27017/test');` if your database has auth enabled 282 | } 283 | ``` 284 | - Mongoose **Schema** : Each schema maps to a MongoDB collection and defines the shape of the documents within that collection. 285 | 286 | ```javascript 287 | const productSchema = new Schema({ 288 | 289 | title: {type: String, required: true, unique: true} , 290 | description: String, 291 | price: {type: Number, min:[0,'wrong price'],required: true}, 292 | discountPercentage: {type: Number, min:[0,'wrong min discount'], max:[50,'wrong max discount']}, 293 | rating: {type: Number, min:[0,'wrong min rating'], max:[5,'wrong max rating']}, 294 | brand: {type: String,required: true}, 295 | category: {type: String, required: true}, 296 | thumbnail: {type: String, required: true}, 297 | images: [ String ] 298 | 299 | }); 300 | ``` 301 | 302 | - Mongoose **Model** : model are built using a combination of Schema and name of Collection. 303 | ```javascript 304 | const Product = mongoose.model('Product', productSchema); 305 | ``` 306 | 307 | - Mongoose **Document** - its is instance of a model. so Model is like a class and documents are like its objects. These documents are directly saved in mongoDB. 308 | ```javascript 309 | const document = new Product(); 310 | // document is actually saved in database after save() 311 | await document.save(); 312 | ``` 313 | 314 | Mongoose Schema/Model can act as **Model** of **Model**-View-Controller concept. 315 | 316 | ### CRUD API and mongoose methods 317 | 318 | **CREATE** : 319 | 1. **create product** - use **POST ** HTTP Method 320 | 321 | ```javascript 322 | const product = new Product(); 323 | await product.save() 324 | ``` 325 | 326 | **READ** : 327 | 328 | 1. **read all products** - use **GET** HTTP Method 329 | ```javascript 330 | const products = await Product.find(); 331 | 332 | const products = await Product.find({price:{$gt:500}}); 333 | ``` 334 | 2. **read 1 product** - use **GET** HTTP Method 335 | ```javascript 336 | const product = await Product.findById(id); 337 | ``` 338 | 339 | **UPDATE** : 340 | 341 | 1. replace product fields (all fields) - use **PUT** HTTP Method 342 | ```javascript 343 | const doc = await Product.findOneAndReplace({_id:id},req.body,{new:true}) 344 | ``` 345 | 346 | 2. update only some product fields - use **PATCH** HTTP Method 347 | 348 | ```javascript 349 | const doc = await Product.findOneAndUpdate({_id:id},req.body,{new:true}) 350 | ``` 351 | 352 | 353 | **DELETE** : 354 | 1. delete 1 product - use **DELETE** HTTP Method 355 | ```javascript 356 | const doc = await Product.findOneAndDelete({_id:id}) 357 | ``` 358 | 359 | ### [[ Assignments ]] 360 | 361 | - **Assignment 1** : Make a Schema for `user` with `userSchema` which has these conditions : 362 | - `firstName` is required, maximum length 16 chars 363 | - `lastName` is not required, maximum length 16 chars 364 | - `age` is a Number, minimum value 12, maximum 100 365 | - `email` make a validator of email, as given in mongoose documentation. 366 | - `address` make address a nested data structure which has its own Schema [ **AddressSchema** ??] [ Hint: check mongoose documentation for sub-documents to do it 367 | 368 | Create `addressSchema` needed in above example as : 369 | - `pincode` : Number, required 370 | - `street` : String, required 371 | - `phone`: String, length=10 372 | 373 | Now try to create this **user** object and **save** it to database. 374 | - What happens to **addresses** ? How address **document** is stored ? check if it creates a **new collection** in database 375 | - What happens if you don't provide validated data in any field. [Note: Throw proper errors strings ] -------------------------------------------------------------------------------- /Mongoose/index.js: -------------------------------------------------------------------------------- 1 | const express = require('express'); 2 | const mongoose = require("mongoose"); 3 | const core = require("cors"); 4 | require("dotenv").config(); 5 | 6 | const app = express(); 7 | 8 | app.use(core()); 9 | app.use(express.json()); 10 | const userRoutes = require("./routes/userrouter"); 11 | app.use("/", userRoutes); 12 | 13 | 14 | mongoose.connect(process.env.CONNECTION_STRING, { 15 | useNewUrlParser: true, 16 | useUnifiedTopology: true, 17 | }); 18 | 19 | const db = mongoose.connection; 20 | 21 | 22 | db.on("error", (error) => { 23 | console.log("Mongodb error : ", error); 24 | }); 25 | 26 | // 2- scenario when mongodb connected 27 | 28 | db.once("open", () => { 29 | console.log("Mongodb connected sucessfully!"); 30 | const port = process.env.PORT; 31 | app.listen(port, () => { 32 | console.log(`server is running on ${port} port`); 33 | }); 34 | }); 35 | 36 | 37 | 38 | -------------------------------------------------------------------------------- /Mongoose/models/usermodel.js: -------------------------------------------------------------------------------- 1 | const moongose = require('mongoose'); 2 | const userSchema = new moongose.Schema( 3 | { 4 | _id: moongose.Schema.ObjectId, 5 | firstname: { 6 | type: String, 7 | required: true, 8 | unique: true 9 | }, 10 | lastname: { 11 | type: String, 12 | required: true, 13 | unique: true 14 | }, 15 | age: { 16 | type: Number, 17 | required: true, 18 | unique: true, 19 | min: [14, "your age is below 15"] 20 | }, 21 | email: { 22 | type: String, 23 | required: true, 24 | unique: true, 25 | } 26 | }, 27 | { collection: 'usersData', versionKey: false } 28 | ); 29 | const Users = moongose.model('usersData', userSchema) 30 | module.exports = Users; 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | -------------------------------------------------------------------------------- /Mongoose/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "moongoose", 3 | "version": "1.0.0", 4 | "description": "", 5 | "main": "index.js", 6 | "scripts": { 7 | "start":"nodemon index.js ", 8 | "test": "echo \"Error: no test specified\" && exit 1" 9 | }, 10 | "keywords": [], 11 | "author": "", 12 | "license": "ISC", 13 | "dependencies": { 14 | "cors": "^2.8.5", 15 | "dotenv": "^16.3.1", 16 | "express": "^4.18.2", 17 | "mongoose": "^8.0.2" 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /Mongoose/routes/userrouter.js: -------------------------------------------------------------------------------- 1 | const express = require('express'); 2 | const moongose = require('mongoose'); 3 | const usermodel = require('../models/usermodel'); 4 | const router = express.Router(); 5 | 6 | // POST Data 7 | 8 | router.post('/addUser', async (req, res) => { 9 | try { 10 | const newuser = new usermodel({ 11 | _id: new moongose.Types.ObjectId(), 12 | firstname: req.body.firstname, 13 | lastname: req.body.lastname, 14 | age: req.body.age, 15 | email: req.body.email 16 | }); 17 | const result = await newuser.save(); 18 | console.log(result); 19 | res.json(result) 20 | } catch (error) { 21 | res.status(400).json({ message: "Your Data is not added" }) 22 | console.log(error); 23 | } 24 | }) 25 | 26 | 27 | // GET DATA 28 | 29 | router.get('/users', async (req, res) => { 30 | const useralldata = await usermodel.find(); 31 | res.json(useralldata); 32 | }) 33 | 34 | // GET DATA By Id 35 | 36 | router.get('/users/:id', async (req, res) => { 37 | try { 38 | const userbyId = req.params.id; 39 | const userdataId = await usermodel.findById(userbyId); 40 | if (!userdataId) { 41 | return res.status(404).json("User Not Found") 42 | } else { 43 | res.status(200).json(userdataId); 44 | } 45 | } catch (error) { 46 | return res.status(500).json(error) 47 | } 48 | }) 49 | 50 | // DELETE DATA By Id 51 | router.delete('/delUser/:id', async (req, res) => { 52 | try { 53 | const userbyId = req.params.id; 54 | const userdataId = await usermodel.findByIdAndDelete(userbyId); 55 | if (!userdataId) { 56 | return res.status(404).json("User Not Found") 57 | } else { 58 | res.status(200).json(userdataId); 59 | } 60 | } catch (error) { 61 | return res.status(500).json(error) 62 | } 63 | 64 | }) 65 | 66 | 67 | // UPDATE USER By Id 68 | 69 | router.put('/updUser/:id', async (req, res) => { 70 | try { 71 | const userbyId = req.params.id; 72 | const dataupdated = new usermodel({ 73 | firstname: req.body.firstname, 74 | lastname: req.body.lastname, 75 | age: req.body.age, 76 | email: req.body.email, 77 | }) 78 | const updateddata = await usermodel.findByIdAndUpdate(userbyId, dataupdated, { 79 | new: true 80 | }) 81 | console.log(updateddata); 82 | if (!updateddata) { 83 | return res.status(404).json("User Not Found") 84 | } else { 85 | res.status(200).json(updateddata); 86 | } 87 | } catch (error) { 88 | return res.status(500).json(error) 89 | } 90 | console.log(error); 91 | }) 92 | 93 | 94 | module.exports = router; -------------------------------------------------------------------------------- /Node Class 01/.gitignore: -------------------------------------------------------------------------------- 1 | node_modules -------------------------------------------------------------------------------- /Node Class 01/README.md: -------------------------------------------------------------------------------- 1 | 2 | ## Chapter 1 - Introduction to Node, NPM, Package.JSON 3 | 4 | ### [[ Chapter Notes ]] 5 | 6 | - **Node JS** installation from official site nodejs.org - use only LTS versions 7 | - Use **terminal / command prompt** to check installation : 8 | ``` node -v ``` 9 | ```npm -v ``` 10 | - **VS Code** installation directly from code.visualstudio.com site 11 | - Use VS code terminal to run **commands** 12 | - **Node REPL** interface can be used directly by typing `node` in **terminal / command prompt** . Use **Ctrl+D** to exit interface. Use **CTRL+C** to exit terminal 13 | - Running any JavaScript file from node using `node filename.js` 14 | - **Modules** are basic containers in Node/JavaScript system. 1 file can be one module in Javascript. 15 | - Two type of Module Systems in node JS are - **CommonJS** module and **ES** Modules. 16 | -------------------------------------------------------------------------------- /Node Class 01/index.js: -------------------------------------------------------------------------------- 1 | const thisApp = require('./this.js') 2 | 3 | 4 | console.log(thisApp) 5 | 6 | const fs = require('fs') 7 | // const txt = fs.readFileSync('./intro.txt' , 'utf-8') 8 | 9 | 10 | const text = fs.readFile('./intro.txt' , 'utf-8' ,(err , text)=>{ 11 | console.log(text) 12 | }) 13 | 14 | -------------------------------------------------------------------------------- /Node Class 01/intro.txt: -------------------------------------------------------------------------------- 1 | Hello I am Muhammad Arham! 2 | I am fine Done. 3 | What's About you? -------------------------------------------------------------------------------- /Node Class 01/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "node-practice", 3 | "version": "1.0.0", 4 | "description": "This is my node practice", 5 | "main": "index.js", 6 | "scripts": { 7 | "start": "node index.js", 8 | "dev":"nodemon index.js", 9 | "test": "echo \"Error: no test specified\" && exit 1" 10 | }, 11 | "author": "", 12 | "license": "ISC", 13 | "dependencies": { 14 | "express": "^4.18.2" 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /Node Class 01/this.js: -------------------------------------------------------------------------------- 1 | const done = " File System Function Done" ; 2 | const github = "Update Commit"; 3 | 4 | const done1 = done.trim(); 5 | 6 | module.exports = done1; -------------------------------------------------------------------------------- /Node Class 02/README.md: -------------------------------------------------------------------------------- 1 | 2 | ## Chapter 2 - Server Concepts with Node - http module 3 | 4 | ### [[ Chapter Notes ]] 5 | 6 | #### HTTP requests 7 | 8 | Request object comprises of many properties, but important ones are : 9 | 10 | - **Type of Request** : GET, POST, PUT, DELETE etc. 11 | - **Headers** : Meta data sent by your browser like browser name, cookies, authentication information etc. 12 | - **Query Parameters** (url?`name=john`) : This is used in GET requests to send data to server 13 | - **Route Params** (url/`john`) 14 | - **Body data** : This is used in POST and other requests to send data to server 15 | 16 | #### HTTP responses 17 | 18 | Response object comprises of many properties, but important ones are : 19 | 20 | - **Headers** : Meta data sent by your server back to client like server name, content size, last updated time etc. 21 | - **Response status code** (`200`, `404`, `403`, `502`) 22 | - **Response body** : Actual data to be sent to client : HTML, JS, JSON, CSS, Image etc. 23 | 24 | #### More info 25 | 26 | - HTTP requests and responses can be tracked from **Dev Tools** > **Network Tab** 27 | - In Node, we can use core **http** module to create a Server which listens to requests, modify data in-between and provides responses. Server needs a **PORT** to be bound to - use only port number > 1024. 28 | - Server can simply be said as **a function which receives a request and returns a response**. [ This is just for understanding] 29 | - There are many **Headers** which exists on request and responses - shared a link below with list of existing headers. 30 | 31 | - We can use Server to do 3 things: 32 | - **Static file Hosting** : Sending normal files without formatting or modifying. 33 | - **Server Side Rendering** : Mixing data with templates and rendering dynamic views (dynamic web pages) 34 | - **Web APIs** : Sending data via some APIs/ endpoints. 35 | 36 | - Every Request has one and only one response. If there is more than 1 response which you want to send - you will encounter a error - "*Headers already sent*" 37 | - POSTMAN is a software for doing complex API requests. -------------------------------------------------------------------------------- /Node Class 02/error.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | Error Page 7 | 8 | 9 | 10 |

404 ERROR

11 |

Page Not Found

12 | 13 | -------------------------------------------------------------------------------- /Node Class 02/index.html: -------------------------------------------------------------------------------- 1 | 5 | 9 | 210 | 211 |
212 |
213 |
214 |
215 |
216 |
217 |
218 | -25% 219 | 220 |
221 |
222 | 223 | 227 |
228 | 229 |
230 |
231 |
***title***
232 | 233 |
234 | ₹ ***price*** 235 | ₹ 700 236 |
237 |
238 | 239 | 240 | 241 |
242 |
243 | 244 | ***rating*** 245 |
246 | 247 | ***buy*** 248 |
249 |
250 |
251 | 252 | 253 |
254 | 255 |
256 |
-------------------------------------------------------------------------------- /Node Class 02/index.js: -------------------------------------------------------------------------------- 1 | const http = require('http') 2 | const fs = require('fs') 3 | const readfs = fs.readFileSync('./index.html', 'utf-8') 4 | const jsondata = JSON.parse(fs.readFileSync('./data.json', 'utf-8')); 5 | const error = fs.readFileSync('./error.html', 'utf-8') 6 | const product = jsondata.products; 7 | 8 | 9 | 10 | 11 | const server = http.createServer((req, res) => { 12 | if (req.url.startsWith('/product')) { 13 | const id = req.url.split('/')[2]; 14 | const newprd = product.find(p => p.id === (+id)); 15 | console.log(newprd); 16 | 17 | if (newprd) { 18 | res.setHeader("Content-Type", "text/html"); 19 | const modifydata = readfs 20 | .replace('***title***', newprd.title) 21 | .replace('***price***', newprd.price) 22 | .replace('***rating***', newprd.rating) 23 | .replace('***url***', newprd.thumbnail) 24 | .replace('***buy***', newprd.brand); 25 | res.end(modifydata); 26 | } else { 27 | } 28 | return; 29 | } 30 | 31 | switch (req.url) { 32 | case "/": 33 | res.setHeader("Content-Type", "text/html") 34 | res.end(readfs) 35 | break; 36 | case "/api": 37 | res.setHeader("Content-Type", "application/json") 38 | res.end(JSON.stringify(jsondata)); 39 | break; 40 | default: 41 | res.setHeader("Content-Type", "text/html") 42 | res.end(error) 43 | 44 | } 45 | console.log("Server Started") 46 | }) 47 | server.listen(8080); 48 | -------------------------------------------------------------------------------- /Node Class 02/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "node-class-02", 3 | "version": "1.0.0", 4 | "description": "", 5 | "main": "index.js", 6 | "scripts": { 7 | "start":"nodemon index.js", 8 | "test": "echo \"Error: no test specified\" && exit 1" 9 | }, 10 | "keywords": [], 11 | "author": "", 12 | "license": "ISC" 13 | } 14 | -------------------------------------------------------------------------------- /Node.JS/Get started instructions.txt: -------------------------------------------------------------------------------- 1 | 1 - Run npm init --> to initialize the package.json file 2 | 3 | 2 - npm install -g nodemon ---> nodemon is a utility that monitors for changes in files in a Node.js 4 | application and automatically restarts the server when changes are detected. 5 | 6 | 3 - npm install cors dotenv mongoose express--save-dev nodemon ---> Basic dependencies to create a server 7 | 8 | 4 - Importing libraries in index.js file 9 | 10 | const express = require("express"); ---> Node.js web application framework used for building web applications and APIs. 11 | const mongoose = require("mongoose"); ---> Provides an elegant and simpler way to work with MongoDB 12 | const cors = require("cors"); ---> Enable or disable cross-origin requests, allowing or restricting access to resources on a web server from different domains. 13 | const app = express(); ---> Creates an instance of the Express application, which is used to define routes, middleware, and handle HTTP requests. 14 | require("dotenv").config(); 15 | app.use(cors()); ---> Adds CORS middleware to the Express application. It allows cross-origin requests from any domain by default. 16 | This is a common configuration for development purposes but may need to be more restrictive in a production environment. 17 | 5 - setup routes 18 | 19 | const gradeRoutes = require("./src/routes/GradeRoutes"); 20 | app.use(`/`, gradeRoutes); 21 | 22 | 6 - connect to mongodb 23 | 24 | mongoose.connect(process.env.CONNECTION_STRING, { 25 | 26 | useNewUrlParser: true, ---> used for compatibility with older MongoDB driver versions 27 | 28 | useUnifiedTopology: true, ---> used to enable the new unified topology engine in MongoDB. 29 | 30 | Explanation ---> enabling the unified topology engine by setting useUnifiedTopology: true 31 | in your Mongoose connection configuration ensures that your Node.js application 32 | uses the most efficient and up-to-date connection management and communication methods 33 | when interacting with your MongoDB database. It's a recommended practice when working 34 | with modern MongoDB versions and the Node.js driver. 35 | }); 36 | 37 | 7- Checking connection is connected successfuly or not 38 | 39 | const db = mongoose.connection; 40 | db.on("error", console.error.bind(console, "connection error:")); 41 | db.once("open", () => { 42 | console.log("Connected to MongoDB"); 43 | 44 | // once connected, start the server 45 | app.listen(3000, () => { 46 | console.log("Server listening on port 3000"); 47 | }); 48 | }); 49 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Welcome to the Backend Development repository! 2 | 3 | This repository has been created to provide you with practical examples of the concepts covered in each class. My goal is to help you better understand the theoretical concepts by providing you with real-world scenarios and code samples. 4 | 5 | ## Why Use This Repository? 6 | 7 | My repository is designed to help you take your development skills to the next level. The code samples contained within cover a wide range of topics, from basic programming concepts to advanced web development techniques. By studying these samples, you'll be able to apply the knowledge you've gained in class to practical situations, and build a strong foundation of development skills. 8 | -------------------------------------------------------------------------------- /REST-API/.gitignore: -------------------------------------------------------------------------------- 1 | node_modules -------------------------------------------------------------------------------- /REST-API/README.md: -------------------------------------------------------------------------------- 1 | 2 | ## Chapter 4 - REST API using Express JS 3 | 4 | 5 | 6 | ### [[ Reading Material ]] 7 | 8 | #### HTTP Methods 9 | 10 | The HTTP method is the type of request you send to the server. You can choose from these five types below: 11 | 12 | - `GET` : This request is used to get a resource from a server. If you perform a `GET` request, the server looks for the data you requested and sends it back to you. In other words a `GET` request performs a `READ` operation. This is the default request method. 13 | 14 | - `POST` This request is used to create a new resource on a server. If you perform a `POST` request, the server creates a new entry in the database and tells you whether the creation is successful. In other words, a `POST` request performs an `CREATE` operation. 15 | 16 | - `PUT` and `PATCH`: These two requests are used to update a resource on a server. If you perform a `PUT` or `PATCH` request, the server updates an entry in the database and tells you whether the update is successful. In other words, a `PUT` or `PATCH` request performs an `UPDATE` operation. 17 | 18 | - `DELETE` : This request is used to delete a resource from a server. If you perform a `DELETE` request, the server deletes an entry in the database and tells you whether the deletion is successful. In other words, a `DELETE` request performs a `DELETE` operation. 19 | 20 | 21 | **REST API** are a combination of METHODS( GET, POST etc) , PATH (based on resource name) 22 | 23 | Suppose you have a resource named `task`, Here is the example of 5 REST APIs commonly available for task. 24 | 25 | 1. **READ APIs :** 26 | 27 | - GET `\tasks` : to read all 28 | 29 | - GET `\task\:id` : to read a particular task which can be identified by unique `id` 30 | 31 | 32 | 2. **CREATE APIs :** 33 | 34 | - POST `\tasks` : to create a new task object (data will go inside request body) 35 | 36 | 3. **UPDATE APIs :** 37 | 38 | - PUT `\task\:id` : to update a particular task which can be identified by unique `id`. Data to be updated will be sent in the request body. Document data will be generally **totally replaced.** 39 | - PATCH `\task\:id` : to update a particular task which can be identified by unique `id`. Data to be updated will be sent in the request body. Only few fields will be replace which are sent in **request body** 40 | 41 | 4. **DELETE APIs** : 42 | 43 | - DELETE `\task\:id` : to delete a particular task which can be identified by unique `id`. 44 | 45 | ### [[ Chapter Notes ]] 46 | 47 | - **REST API** is a standard for making APIs. 48 | - We have to consider a resource which we want to access - like **Product** 49 | - We access **Product** using combination of HTTP method and URL style 50 | 51 | **REST API ( CRUD - Create , Read , Update, Delete) :** 52 | 53 | - **CREATE** 54 | - **POST** /products - create a new resource (product) 55 | 56 | - **READ** 57 | - **GET** /products - read many resources (products) 58 | - **GET** /products/:id - read one specific resource (product) 59 | 60 | - **UPDATE** 61 | - **PUT** /products/:id - update by replacing all content of specific resource (product). 62 | - **PATCH** /products/:id - update by only setting content from body of request and not replacing other parts of specific resource (product). 63 | 64 | - **DELETE** 65 | - **DELETE** /products/:id - delete a specific resource (product). 66 | 67 | 68 | 69 | 70 | ### [[ Assignments ]] 71 | 72 | - **Assignment 1** : Make an API similar to explained above for `Quotes` take dummy data from same site ([dummy json quotes](https://dummyjson.com/quotes)) 73 | -------------------------------------------------------------------------------- /REST-API/RESTAPI.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/arhamansari11/Backend-Developement/f0765184454f09164178677f8fb0c52ef40c64b4/REST-API/RESTAPI.png -------------------------------------------------------------------------------- /REST-API/data.json: -------------------------------------------------------------------------------- 1 | { 2 | "products": [ 3 | { 4 | "id": 1, 5 | "title": "iPhone 9", 6 | "description": "An apple mobile which is nothing like apple", 7 | "price": 549, 8 | "discountPercentage": 12.96, 9 | "rating": 4.69, 10 | "stock": 94, 11 | "brand": "Apple", 12 | "category": "smartphones", 13 | "thumbnail": "https://i.dummyjson.com/data/products/1/thumbnail.jpg", 14 | "images": [ 15 | "https://i.dummyjson.com/data/products/1/1.jpg", 16 | "https://i.dummyjson.com/data/products/1/2.jpg", 17 | "https://i.dummyjson.com/data/products/1/3.jpg", 18 | "https://i.dummyjson.com/data/products/1/4.jpg", 19 | "https://i.dummyjson.com/data/products/1/thumbnail.jpg" 20 | ] 21 | }, 22 | { 23 | "id": 2, 24 | "title": "iPhone X", 25 | "description": "SIM-Free, Model A19211 6.5-inch Super Retina HD display with OLED technology A12 Bionic chip with ...", 26 | "price": 899, 27 | "discountPercentage": 17.94, 28 | "rating": 4.44, 29 | "stock": 34, 30 | "brand": "Apple", 31 | "category": "smartphones", 32 | "thumbnail": "https://i.dummyjson.com/data/products/2/thumbnail.jpg", 33 | "images": [ 34 | "https://i.dummyjson.com/data/products/2/1.jpg", 35 | "https://i.dummyjson.com/data/products/2/2.jpg", 36 | "https://i.dummyjson.com/data/products/2/3.jpg", 37 | "https://i.dummyjson.com/data/products/2/thumbnail.jpg" 38 | ] 39 | }, 40 | { 41 | "id": 3, 42 | "title": "Samsung Universe 9", 43 | "description": "Samsung's new variant which goes beyond Galaxy to the Universe", 44 | "price": 1249, 45 | "discountPercentage": 15.46, 46 | "rating": 4.09, 47 | "stock": 36, 48 | "brand": "Samsung", 49 | "category": "smartphones", 50 | "thumbnail": "https://i.dummyjson.com/data/products/3/thumbnail.jpg", 51 | "images": ["https://i.dummyjson.com/data/products/3/1.jpg"] 52 | }, 53 | { 54 | "id": 4, 55 | "title": "OPPOF19", 56 | "description": "OPPO F19 is officially announced on April 2021.", 57 | "price": 280, 58 | "discountPercentage": 17.91, 59 | "rating": 4.3, 60 | "stock": 123, 61 | "brand": "OPPO", 62 | "category": "smartphones", 63 | "thumbnail": "https://i.dummyjson.com/data/products/4/thumbnail.jpg", 64 | "images": [ 65 | "https://i.dummyjson.com/data/products/4/1.jpg", 66 | "https://i.dummyjson.com/data/products/4/2.jpg", 67 | "https://i.dummyjson.com/data/products/4/3.jpg", 68 | "https://i.dummyjson.com/data/products/4/4.jpg", 69 | "https://i.dummyjson.com/data/products/4/thumbnail.jpg" 70 | ] 71 | }, 72 | { 73 | "id": 5, 74 | "title": "Huawei P30", 75 | "description": "Huawei’s re-badged P30 Pro New Edition was officially unveiled yesterday in Germany and now the device has made its way to the UK.", 76 | "price": 499, 77 | "discountPercentage": 10.58, 78 | "rating": 4.09, 79 | "stock": 32, 80 | "brand": "Huawei", 81 | "category": "smartphones", 82 | "thumbnail": "https://i.dummyjson.com/data/products/5/thumbnail.jpg", 83 | "images": [ 84 | "https://i.dummyjson.com/data/products/5/1.jpg", 85 | "https://i.dummyjson.com/data/products/5/2.jpg", 86 | "https://i.dummyjson.com/data/products/5/3.jpg" 87 | ] 88 | }, 89 | { 90 | "id": 6, 91 | "title": "MacBook Pro", 92 | "description": "MacBook Pro 2021 with mini-LED display may launch between September, November", 93 | "price": 1749, 94 | "discountPercentage": 11.02, 95 | "rating": 4.57, 96 | "stock": 83, 97 | "brand": "Apple", 98 | "category": "laptops", 99 | "thumbnail": "https://i.dummyjson.com/data/products/6/thumbnail.png", 100 | "images": [ 101 | "https://i.dummyjson.com/data/products/6/1.png", 102 | "https://i.dummyjson.com/data/products/6/2.jpg", 103 | "https://i.dummyjson.com/data/products/6/3.png", 104 | "https://i.dummyjson.com/data/products/6/4.jpg" 105 | ] 106 | }, 107 | { 108 | "id": 7, 109 | "title": "Samsung Galaxy Book", 110 | "description": "Samsung Galaxy Book S (2020) Laptop With Intel Lakefield Chip, 8GB of RAM Launched", 111 | "price": 1499, 112 | "discountPercentage": 4.15, 113 | "rating": 4.25, 114 | "stock": 50, 115 | "brand": "Samsung", 116 | "category": "laptops", 117 | "thumbnail": "https://i.dummyjson.com/data/products/7/thumbnail.jpg", 118 | "images": [ 119 | "https://i.dummyjson.com/data/products/7/1.jpg", 120 | "https://i.dummyjson.com/data/products/7/2.jpg", 121 | "https://i.dummyjson.com/data/products/7/3.jpg", 122 | "https://i.dummyjson.com/data/products/7/thumbnail.jpg" 123 | ] 124 | }, 125 | { 126 | "id": 8, 127 | "title": "Microsoft Surface Laptop 4", 128 | "description": "Style and speed. Stand out on HD video calls backed by Studio Mics. Capture ideas on the vibrant touchscreen.", 129 | "price": 1499, 130 | "discountPercentage": 10.23, 131 | "rating": 4.43, 132 | "stock": 68, 133 | "brand": "Microsoft Surface", 134 | "category": "laptops", 135 | "thumbnail": "https://i.dummyjson.com/data/products/8/thumbnail.jpg", 136 | "images": [ 137 | "https://i.dummyjson.com/data/products/8/1.jpg", 138 | "https://i.dummyjson.com/data/products/8/2.jpg", 139 | "https://i.dummyjson.com/data/products/8/3.jpg", 140 | "https://i.dummyjson.com/data/products/8/4.jpg", 141 | "https://i.dummyjson.com/data/products/8/thumbnail.jpg" 142 | ] 143 | }, 144 | { 145 | "id": 9, 146 | "title": "Infinix INBOOK", 147 | "description": "Infinix Inbook X1 Ci3 10th 8GB 256GB 14 Win10 Grey – 1 Year Warranty", 148 | "price": 1099, 149 | "discountPercentage": 11.83, 150 | "rating": 4.54, 151 | "stock": 96, 152 | "brand": "Infinix", 153 | "category": "laptops", 154 | "thumbnail": "https://i.dummyjson.com/data/products/9/thumbnail.jpg", 155 | "images": [ 156 | "https://i.dummyjson.com/data/products/9/1.jpg", 157 | "https://i.dummyjson.com/data/products/9/2.png", 158 | "https://i.dummyjson.com/data/products/9/3.png", 159 | "https://i.dummyjson.com/data/products/9/4.jpg", 160 | "https://i.dummyjson.com/data/products/9/thumbnail.jpg" 161 | ] 162 | }, 163 | { 164 | "id": 10, 165 | "title": "HP Pavilion 15-DK1056WM", 166 | "description": "HP Pavilion 15-DK1056WM Gaming Laptop 10th Gen Core i5, 8GB, 256GB SSD, GTX 1650 4GB, Windows 10", 167 | "price": 1099, 168 | "discountPercentage": 6.18, 169 | "rating": 4.43, 170 | "stock": 89, 171 | "brand": "HP Pavilion", 172 | "category": "laptops", 173 | "thumbnail": "https://i.dummyjson.com/data/products/10/thumbnail.jpeg", 174 | "images": [ 175 | "https://i.dummyjson.com/data/products/10/1.jpg", 176 | "https://i.dummyjson.com/data/products/10/2.jpg", 177 | "https://i.dummyjson.com/data/products/10/3.jpg", 178 | "https://i.dummyjson.com/data/products/10/thumbnail.jpeg" 179 | ] 180 | }, 181 | { 182 | "id": 11, 183 | "title": "perfume Oil", 184 | "description": "Mega Discount, Impression of Acqua Di Gio by GiorgioArmani concentrated attar perfume Oil", 185 | "price": 13, 186 | "discountPercentage": 8.4, 187 | "rating": 4.26, 188 | "stock": 65, 189 | "brand": "Impression of Acqua Di Gio", 190 | "category": "fragrances", 191 | "thumbnail": "https://i.dummyjson.com/data/products/11/thumbnail.jpg", 192 | "images": [ 193 | "https://i.dummyjson.com/data/products/11/1.jpg", 194 | "https://i.dummyjson.com/data/products/11/2.jpg", 195 | "https://i.dummyjson.com/data/products/11/3.jpg", 196 | "https://i.dummyjson.com/data/products/11/thumbnail.jpg" 197 | ] 198 | }, 199 | { 200 | "id": 12, 201 | "title": "Brown Perfume", 202 | "description": "Royal_Mirage Sport Brown Perfume for Men & Women - 120ml", 203 | "price": 40, 204 | "discountPercentage": 15.66, 205 | "rating": 4, 206 | "stock": 52, 207 | "brand": "Royal_Mirage", 208 | "category": "fragrances", 209 | "thumbnail": "https://i.dummyjson.com/data/products/12/thumbnail.jpg", 210 | "images": [ 211 | "https://i.dummyjson.com/data/products/12/1.jpg", 212 | "https://i.dummyjson.com/data/products/12/2.jpg", 213 | "https://i.dummyjson.com/data/products/12/3.png", 214 | "https://i.dummyjson.com/data/products/12/4.jpg", 215 | "https://i.dummyjson.com/data/products/12/thumbnail.jpg" 216 | ] 217 | }, 218 | { 219 | "id": 13, 220 | "title": "Fog Scent Xpressio Perfume", 221 | "description": "Product details of Best Fog Scent Xpressio Perfume 100ml For Men cool long lasting perfumes for Men", 222 | "price": 13, 223 | "discountPercentage": 8.14, 224 | "rating": 4.59, 225 | "stock": 61, 226 | "brand": "Fog Scent Xpressio", 227 | "category": "fragrances", 228 | "thumbnail": "https://i.dummyjson.com/data/products/13/thumbnail.webp", 229 | "images": [ 230 | "https://i.dummyjson.com/data/products/13/1.jpg", 231 | "https://i.dummyjson.com/data/products/13/2.png", 232 | "https://i.dummyjson.com/data/products/13/3.jpg", 233 | "https://i.dummyjson.com/data/products/13/4.jpg", 234 | "https://i.dummyjson.com/data/products/13/thumbnail.webp" 235 | ] 236 | }, 237 | { 238 | "id": 14, 239 | "title": "Non-Alcoholic Concentrated Perfume Oil", 240 | "description": "Original Al Munakh® by Mahal Al Musk | Our Impression of Climate | 6ml Non-Alcoholic Concentrated Perfume Oil", 241 | "price": 120, 242 | "discountPercentage": 15.6, 243 | "rating": 4.21, 244 | "stock": 114, 245 | "brand": "Al Munakh", 246 | "category": "fragrances", 247 | "thumbnail": "https://i.dummyjson.com/data/products/14/thumbnail.jpg", 248 | "images": [ 249 | "https://i.dummyjson.com/data/products/14/1.jpg", 250 | "https://i.dummyjson.com/data/products/14/2.jpg", 251 | "https://i.dummyjson.com/data/products/14/3.jpg", 252 | "https://i.dummyjson.com/data/products/14/thumbnail.jpg" 253 | ] 254 | }, 255 | { 256 | "id": 15, 257 | "title": "Eau De Perfume Spray", 258 | "description": "Genuine Al-Rehab spray perfume from UAE/Saudi Arabia/Yemen High Quality", 259 | "price": 30, 260 | "discountPercentage": 10.99, 261 | "rating": 4.7, 262 | "stock": 105, 263 | "brand": "Lord - Al-Rehab", 264 | "category": "fragrances", 265 | "thumbnail": "https://i.dummyjson.com/data/products/15/thumbnail.jpg", 266 | "images": [ 267 | "https://i.dummyjson.com/data/products/15/1.jpg", 268 | "https://i.dummyjson.com/data/products/15/2.jpg", 269 | "https://i.dummyjson.com/data/products/15/3.jpg", 270 | "https://i.dummyjson.com/data/products/15/4.jpg", 271 | "https://i.dummyjson.com/data/products/15/thumbnail.jpg" 272 | ] 273 | }, 274 | { 275 | "id": 16, 276 | "title": "Hyaluronic Acid Serum", 277 | "description": "L'Oréal Paris introduces Hyaluron Expert Replumping Serum formulated with 1.5% Hyaluronic Acid", 278 | "price": 19, 279 | "discountPercentage": 13.31, 280 | "rating": 4.83, 281 | "stock": 110, 282 | "brand": "L'Oreal Paris", 283 | "category": "skincare", 284 | "thumbnail": "https://i.dummyjson.com/data/products/16/thumbnail.jpg", 285 | "images": [ 286 | "https://i.dummyjson.com/data/products/16/1.png", 287 | "https://i.dummyjson.com/data/products/16/2.webp", 288 | "https://i.dummyjson.com/data/products/16/3.jpg", 289 | "https://i.dummyjson.com/data/products/16/4.jpg", 290 | "https://i.dummyjson.com/data/products/16/thumbnail.jpg" 291 | ] 292 | }, 293 | { 294 | "id": 17, 295 | "title": "Tree Oil 30ml", 296 | "description": "Tea tree oil contains a number of compounds, including terpinen-4-ol, that have been shown to kill certain bacteria,", 297 | "price": 12, 298 | "discountPercentage": 4.09, 299 | "rating": 4.52, 300 | "stock": 78, 301 | "brand": "Hemani Tea", 302 | "category": "skincare", 303 | "thumbnail": "https://i.dummyjson.com/data/products/17/thumbnail.jpg", 304 | "images": [ 305 | "https://i.dummyjson.com/data/products/17/1.jpg", 306 | "https://i.dummyjson.com/data/products/17/2.jpg", 307 | "https://i.dummyjson.com/data/products/17/3.jpg", 308 | "https://i.dummyjson.com/data/products/17/thumbnail.jpg" 309 | ] 310 | }, 311 | { 312 | "id": 18, 313 | "title": "Oil Free Moisturizer 100ml", 314 | "description": "Dermive Oil Free Moisturizer with SPF 20 is specifically formulated with ceramides, hyaluronic acid & sunscreen.", 315 | "price": 40, 316 | "discountPercentage": 13.1, 317 | "rating": 4.56, 318 | "stock": 88, 319 | "brand": "Dermive", 320 | "category": "skincare", 321 | "thumbnail": "https://i.dummyjson.com/data/products/18/thumbnail.jpg", 322 | "images": [ 323 | "https://i.dummyjson.com/data/products/18/1.jpg", 324 | "https://i.dummyjson.com/data/products/18/2.jpg", 325 | "https://i.dummyjson.com/data/products/18/3.jpg", 326 | "https://i.dummyjson.com/data/products/18/4.jpg", 327 | "https://i.dummyjson.com/data/products/18/thumbnail.jpg" 328 | ] 329 | }, 330 | { 331 | "id": 19, 332 | "title": "Skin Beauty Serum.", 333 | "description": "Product name: rorec collagen hyaluronic acid white face serum riceNet weight: 15 m", 334 | "price": 46, 335 | "discountPercentage": 10.68, 336 | "rating": 4.42, 337 | "stock": 54, 338 | "brand": "ROREC White Rice", 339 | "category": "skincare", 340 | "thumbnail": "https://i.dummyjson.com/data/products/19/thumbnail.jpg", 341 | "images": [ 342 | "https://i.dummyjson.com/data/products/19/1.jpg", 343 | "https://i.dummyjson.com/data/products/19/2.jpg", 344 | "https://i.dummyjson.com/data/products/19/3.png", 345 | "https://i.dummyjson.com/data/products/19/thumbnail.jpg" 346 | ] 347 | }, 348 | { 349 | "id": 20, 350 | "title": "Freckle Treatment Cream- 15gm", 351 | "description": "Fair & Clear is Pakistan's only pure Freckle cream which helpsfade Freckles, Darkspots and pigments. Mercury level is 0%, so there are no side effects.", 352 | "price": 70, 353 | "discountPercentage": 16.99, 354 | "rating": 4.06, 355 | "stock": 140, 356 | "brand": "Fair & Clear", 357 | "category": "skincare", 358 | "thumbnail": "https://i.dummyjson.com/data/products/20/thumbnail.jpg", 359 | "images": [ 360 | "https://i.dummyjson.com/data/products/20/1.jpg", 361 | "https://i.dummyjson.com/data/products/20/2.jpg", 362 | "https://i.dummyjson.com/data/products/20/3.jpg", 363 | "https://i.dummyjson.com/data/products/20/4.jpg", 364 | "https://i.dummyjson.com/data/products/20/thumbnail.jpg" 365 | ] 366 | }, 367 | { 368 | "id": 21, 369 | "title": "- Daal Masoor 500 grams", 370 | "description": "Fine quality Branded Product Keep in a cool and dry place", 371 | "price": 20, 372 | "discountPercentage": 4.81, 373 | "rating": 4.44, 374 | "stock": 133, 375 | "brand": "Saaf & Khaas", 376 | "category": "groceries", 377 | "thumbnail": "https://i.dummyjson.com/data/products/21/thumbnail.png", 378 | "images": [ 379 | "https://i.dummyjson.com/data/products/21/1.png", 380 | "https://i.dummyjson.com/data/products/21/2.jpg", 381 | "https://i.dummyjson.com/data/products/21/3.jpg" 382 | ] 383 | }, 384 | { 385 | "id": 22, 386 | "title": "Elbow Macaroni - 400 gm", 387 | "description": "Product details of Bake Parlor Big Elbow Macaroni - 400 gm", 388 | "price": 14, 389 | "discountPercentage": 15.58, 390 | "rating": 4.57, 391 | "stock": 146, 392 | "brand": "Bake Parlor Big", 393 | "category": "groceries", 394 | "thumbnail": "https://i.dummyjson.com/data/products/22/thumbnail.jpg", 395 | "images": [ 396 | "https://i.dummyjson.com/data/products/22/1.jpg", 397 | "https://i.dummyjson.com/data/products/22/2.jpg", 398 | "https://i.dummyjson.com/data/products/22/3.jpg" 399 | ] 400 | }, 401 | { 402 | "id": 23, 403 | "title": "Orange Essence Food Flavou", 404 | "description": "Specifications of Orange Essence Food Flavour For Cakes and Baking Food Item", 405 | "price": 14, 406 | "discountPercentage": 8.04, 407 | "rating": 4.85, 408 | "stock": 26, 409 | "brand": "Baking Food Items", 410 | "category": "groceries", 411 | "thumbnail": "https://i.dummyjson.com/data/products/23/thumbnail.jpg", 412 | "images": [ 413 | "https://i.dummyjson.com/data/products/23/1.jpg", 414 | "https://i.dummyjson.com/data/products/23/2.jpg", 415 | "https://i.dummyjson.com/data/products/23/3.jpg", 416 | "https://i.dummyjson.com/data/products/23/4.jpg", 417 | "https://i.dummyjson.com/data/products/23/thumbnail.jpg" 418 | ] 419 | }, 420 | { 421 | "id": 24, 422 | "title": "cereals muesli fruit nuts", 423 | "description": "original fauji cereal muesli 250gm box pack original fauji cereals muesli fruit nuts flakes breakfast cereal break fast faujicereals cerels cerel foji fouji", 424 | "price": 46, 425 | "discountPercentage": 16.8, 426 | "rating": 4.94, 427 | "stock": 113, 428 | "brand": "fauji", 429 | "category": "groceries", 430 | "thumbnail": "https://i.dummyjson.com/data/products/24/thumbnail.jpg", 431 | "images": [ 432 | "https://i.dummyjson.com/data/products/24/1.jpg", 433 | "https://i.dummyjson.com/data/products/24/2.jpg", 434 | "https://i.dummyjson.com/data/products/24/3.jpg", 435 | "https://i.dummyjson.com/data/products/24/4.jpg", 436 | "https://i.dummyjson.com/data/products/24/thumbnail.jpg" 437 | ] 438 | }, 439 | { 440 | "id": 25, 441 | "title": "Gulab Powder 50 Gram", 442 | "description": "Dry Rose Flower Powder Gulab Powder 50 Gram • Treats Wounds", 443 | "price": 70, 444 | "discountPercentage": 13.58, 445 | "rating": 4.87, 446 | "stock": 47, 447 | "brand": "Dry Rose", 448 | "category": "groceries", 449 | "thumbnail": "https://i.dummyjson.com/data/products/25/thumbnail.jpg", 450 | "images": [ 451 | "https://i.dummyjson.com/data/products/25/1.png", 452 | "https://i.dummyjson.com/data/products/25/2.jpg", 453 | "https://i.dummyjson.com/data/products/25/3.png", 454 | "https://i.dummyjson.com/data/products/25/4.jpg", 455 | "https://i.dummyjson.com/data/products/25/thumbnail.jpg" 456 | ] 457 | }, 458 | { 459 | "id": 26, 460 | "title": "Plant Hanger For Home", 461 | "description": "Boho Decor Plant Hanger For Home Wall Decoration Macrame Wall Hanging Shelf", 462 | "price": 41, 463 | "discountPercentage": 17.86, 464 | "rating": 4.08, 465 | "stock": 131, 466 | "brand": "Boho Decor", 467 | "category": "home-decoration", 468 | "thumbnail": "https://i.dummyjson.com/data/products/26/thumbnail.jpg", 469 | "images": [ 470 | "https://i.dummyjson.com/data/products/26/1.jpg", 471 | "https://i.dummyjson.com/data/products/26/2.jpg", 472 | "https://i.dummyjson.com/data/products/26/3.jpg", 473 | "https://i.dummyjson.com/data/products/26/4.jpg", 474 | "https://i.dummyjson.com/data/products/26/5.jpg", 475 | "https://i.dummyjson.com/data/products/26/thumbnail.jpg" 476 | ] 477 | }, 478 | { 479 | "id": 27, 480 | "title": "Flying Wooden Bird", 481 | "description": "Package Include 6 Birds with Adhesive Tape Shape: 3D Shaped Wooden Birds Material: Wooden MDF, Laminated 3.5mm", 482 | "price": 51, 483 | "discountPercentage": 15.58, 484 | "rating": 4.41, 485 | "stock": 17, 486 | "brand": "Flying Wooden", 487 | "category": "home-decoration", 488 | "thumbnail": "https://i.dummyjson.com/data/products/27/thumbnail.webp", 489 | "images": [ 490 | "https://i.dummyjson.com/data/products/27/1.jpg", 491 | "https://i.dummyjson.com/data/products/27/2.jpg", 492 | "https://i.dummyjson.com/data/products/27/3.jpg", 493 | "https://i.dummyjson.com/data/products/27/4.jpg", 494 | "https://i.dummyjson.com/data/products/27/thumbnail.webp" 495 | ] 496 | }, 497 | { 498 | "id": 28, 499 | "title": "3D Embellishment Art Lamp", 500 | "description": "3D led lamp sticker Wall sticker 3d wall art light on/off button cell operated (included)", 501 | "price": 20, 502 | "discountPercentage": 16.49, 503 | "rating": 4.82, 504 | "stock": 54, 505 | "brand": "LED Lights", 506 | "category": "home-decoration", 507 | "thumbnail": "https://i.dummyjson.com/data/products/28/thumbnail.jpg", 508 | "images": [ 509 | "https://i.dummyjson.com/data/products/28/1.jpg", 510 | "https://i.dummyjson.com/data/products/28/2.jpg", 511 | "https://i.dummyjson.com/data/products/28/3.png", 512 | "https://i.dummyjson.com/data/products/28/4.jpg", 513 | "https://i.dummyjson.com/data/products/28/thumbnail.jpg" 514 | ] 515 | }, 516 | { 517 | "id": 29, 518 | "title": "Handcraft Chinese style", 519 | "description": "Handcraft Chinese style art luxury palace hotel villa mansion home decor ceramic vase with brass fruit plate", 520 | "price": 60, 521 | "discountPercentage": 15.34, 522 | "rating": 4.44, 523 | "stock": 7, 524 | "brand": "luxury palace", 525 | "category": "home-decoration", 526 | "thumbnail": "https://i.dummyjson.com/data/products/29/thumbnail.webp", 527 | "images": [ 528 | "https://i.dummyjson.com/data/products/29/1.jpg", 529 | "https://i.dummyjson.com/data/products/29/2.jpg", 530 | "https://i.dummyjson.com/data/products/29/3.webp", 531 | "https://i.dummyjson.com/data/products/29/4.webp", 532 | "https://i.dummyjson.com/data/products/29/thumbnail.webp" 533 | ] 534 | }, 535 | { 536 | "id": 30, 537 | "title": "Key Holder", 538 | "description": "Attractive DesignMetallic materialFour key hooksReliable & DurablePremium Quality", 539 | "price": 30, 540 | "discountPercentage": 2.92, 541 | "rating": 4.92, 542 | "stock": 54, 543 | "brand": "Golden", 544 | "category": "home-decoration", 545 | "thumbnail": "https://i.dummyjson.com/data/products/30/thumbnail.jpg", 546 | "images": [ 547 | "https://i.dummyjson.com/data/products/30/1.jpg", 548 | "https://i.dummyjson.com/data/products/30/2.jpg", 549 | "https://i.dummyjson.com/data/products/30/3.jpg", 550 | "https://i.dummyjson.com/data/products/30/thumbnail.jpg" 551 | ] 552 | } 553 | ] 554 | } 555 | -------------------------------------------------------------------------------- /REST-API/index.js: -------------------------------------------------------------------------------- 1 | const fs = require('fs') 2 | const jsondata = JSON.parse(fs.readFileSync('./data.json', 'utf-8')); 3 | const product = jsondata.products; 4 | 5 | const express = require('express'); 6 | const server = express() 7 | 8 | 9 | const morgan = require('morgan'); 10 | // server.use(morgan('default')) 11 | 12 | server.use(express.json()); 13 | server.use(express.static("public")); 14 | 15 | 16 | // We call them API-root and also Base URL. 17 | // C R U D 18 | // CREATE READ UPDATE DELETE 19 | 20 | 21 | // 1=> This is POST API usually used for CREATE Data in Database. 22 | // CREATE API 23 | server.post('/products', (req, res) => { 24 | console.log(req.body); 25 | product.push(req.body); 26 | res.json(req.body); 27 | }) 28 | 29 | 30 | 31 | 32 | // 2 => This is GET API usually used for GET Data from Database. 33 | // READ API 34 | server.get('/products', (req, res) => { 35 | res.json(product); 36 | console.log("GET API DONE"); 37 | }) 38 | 39 | // For Get only one product through it's id. 40 | server.get('/products/:id', (req, res) => { 41 | const id = +req.params.id; 42 | const newpd =product.find(p=>p.id===id) 43 | console.log(newpd); 44 | res.json(newpd); 45 | }) 46 | 47 | 48 | 49 | 50 | // 3 => This is UPDATE API usually used for UPDATE Data in Database. 51 | // UPDATE API 52 | server.put('/products/:id', (req, res) => { 53 | const id = +req.params.id; 54 | const newpdIndex =product.findIndex(p=>p.id===id) 55 | product.splice(newpdIndex,1,{...req.body,id:id}) 56 | console.log(newpdIndex); 57 | res.status(202).json(); 58 | }) 59 | 60 | 61 | 62 | // 3 => This is UPDATE API usually used for UPDATE ( Specific ) Data in Database. 63 | // UPDATE API 64 | server.patch('/products/:id', (req, res) => { 65 | const id = +req.params.id; 66 | const newpdIndex =product.findIndex(p=>p.id===id) 67 | const patchdata = product[newpdIndex] 68 | product.splice(newpdIndex,1,{...patchdata , ...req.body}) 69 | console.log(newpdIndex); 70 | res.status(202).json(); 71 | }) 72 | 73 | 74 | 75 | // 4 => This is DELETE API usually used for DELETE Data in Database. 76 | // DELETE API 77 | server.delete('/products/:id', (req, res) => { 78 | const id = +req.params.id; 79 | const newpdIndex =product.findIndex(p=>p.id===id) 80 | const patchdata = product[newpdIndex] 81 | product.splice(newpdIndex,1) 82 | console.log(newpdIndex); 83 | res.status(202).json(); 84 | }) 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | server.listen(8080, () => { 94 | console.log("Server Running on Port 8080"); 95 | }) 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | -------------------------------------------------------------------------------- /REST-API/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "node-class-02", 3 | "version": "1.0.0", 4 | "description": "", 5 | "main": "index.js", 6 | "scripts": { 7 | "start": "nodemon index.js", 8 | "test": "echo \"Error: no test specified\" && exit 1" 9 | }, 10 | "keywords": [], 11 | "author": "", 12 | "license": "ISC", 13 | "dependencies": { 14 | "express": "^4.18.2", 15 | "morgan": "^1.10.0" 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /Softwares.txt: -------------------------------------------------------------------------------- 1 | 1 - Install Node.js 2 | 2 - Install Postman ---> Used for testing api's 3 | Download URL: https://www.postman.com/downloads/ 4 | 3 - Install MongoDb Compass 5 | Download URL : https://www.mongodb.com/try/download/shell -------------------------------------------------------------------------------- /Status Code/Status Code.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/arhamansari11/Backend-Developement/f0765184454f09164178677f8fb0c52ef40c64b4/Status Code/Status Code.pdf -------------------------------------------------------------------------------- /repo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/arhamansari11/Backend-Developement/f0765184454f09164178677f8fb0c52ef40c64b4/repo.png --------------------------------------------------------------------------------