├── .gitignore ├── 00. Complete Notes.md ├── 01_What_is_NodeJS └── Learning.md ├── 02_Node_JS_Installation └── Learning.md ├── 04_Modules_in_NodeJS ├── math.js ├── module.js └── package.json ├── 05_File_Handling_in_NodeJS ├── contacts.txt ├── file.js ├── package.json └── test.txt ├── 06_How_NodeJS_Works ├── blocking.png ├── contacts.txt ├── file.js ├── learning.md ├── non-blocking.png └── package.json ├── 07_Building_HTTP_Server ├── index.js ├── log.txt └── package.json ├── 08_Handling_URL ├── Learning.md ├── index.js ├── log.txt ├── package-lock.json └── package.json ├── 09_HTTP_Methods ├── Learnings.md ├── index.js ├── log.txt ├── package-lock.json └── package.json ├── 10_Getting_Started_with_Express_and_Nodejs ├── index.js ├── log.txt ├── package-lock.json └── package.json ├── 11_How_Versioning_Works_in_NodeJS ├── Learnings.md ├── package-lock.json └── package.json ├── 12_What_is_REST_API ├── 1.png ├── 2.png ├── 3.png ├── 4.png └── Learnings.md ├── 13_Building_REST_API_using_Node_and_Express ├── MOCK_DATA.json ├── index.js ├── package-lock.json ├── package.json └── task.md ├── 14_Intro_to_POSTMAN_for_REST_API ├── MOCK_DATA.json ├── index.js ├── package-lock.json └── package.json ├── 15_Express_Middleware ├── MOCK_DATA.json ├── Readme.md ├── index.js ├── log.txt ├── package-lock.json └── package.json ├── 16_What_are_HTTP_Headers_in_API ├── MOCK_DATA.json ├── Readme.md ├── img1.png ├── img2.png ├── index.js ├── log.txt ├── package-lock.json └── package.json ├── 17_HTTP_Status_Codes ├── MOCK_DATA.json ├── Readme.md ├── index.js ├── package-lock.json └── package.json ├── 18_Getting_Started_with_MongoDB └── Readme.md ├── 19_Connecting_NodeJS_with_MongoDB ├── MOCK_DATA.json ├── Readme.md ├── index.js ├── package-lock.json └── package.json ├── 20_Model_View_Controller_in_NodeJS ├── Readme.md ├── connection.js ├── controllers │ └── user.js ├── index.js ├── log.txt ├── middlewares │ └── index.js ├── models │ └── user.js ├── package-lock.json ├── package.json └── routes │ └── user.js ├── 21_Custom_URL_Shortener ├── connect.js ├── controllers │ └── url.js ├── index.js ├── models │ └── url.js ├── package-lock.json ├── package.json └── routes │ └── url.js ├── 22_Server_Side_Rendering_with_EJS_and_NodeJS ├── Readme.md ├── connect.js ├── controllers │ └── url.js ├── index.js ├── models │ └── url.js ├── package-lock.json ├── package.json ├── routes │ ├── staticRoute.js │ └── url.js └── views │ └── home.ejs ├── 23_Building_Node.js_Authentication_from_Scratch ├── Readme.md ├── connect.js ├── controllers │ ├── url.js │ └── user.js ├── images │ ├── expressflow.png │ └── stateful.png ├── index.js ├── middlewares │ └── auth.js ├── models │ ├── url.js │ └── user.js ├── package-lock.json ├── package.json ├── routes │ ├── staticRoute.js │ ├── url.js │ └── user.js ├── service │ └── auth.js └── views │ ├── home.ejs │ ├── login.ejs │ └── signup.ejs ├── 24_JWT_Authentication_in_NodeJS ├── Readme.md ├── connect.js ├── controllers │ ├── url.js │ └── user.js ├── images │ ├── expressflow.png │ └── stateful.png ├── index.js ├── middlewares │ └── auth.js ├── models │ ├── url.js │ └── user.js ├── package-lock.json ├── package.json ├── routes │ ├── staticRoute.js │ ├── url.js │ └── user.js ├── service │ └── auth.js └── views │ ├── home.ejs │ ├── login.ejs │ └── signup.ejs ├── 25_What_are_Cookies_in_NodeJS ├── Readme.md ├── connect.js ├── controllers │ ├── url.js │ └── user.js ├── index.js ├── middlewares │ └── auth.js ├── models │ ├── url.js │ └── user.js ├── package-lock.json ├── package.json ├── routes │ ├── staticRoute.js │ ├── url.js │ └── user.js ├── service │ └── auth.js └── views │ ├── home.ejs │ ├── login.ejs │ └── signup.ejs ├── 26_Authorization_in_NodeJS ├── Readme.md ├── connect.js ├── controllers │ ├── url.js │ └── user.js ├── index.js ├── middlewares │ └── auth.js ├── models │ ├── url.js │ └── user.js ├── package-lock.json ├── package.json ├── routes │ ├── staticRoute.js │ ├── url.js │ └── user.js ├── service │ └── auth.js └── views │ ├── home.ejs │ ├── login.ejs │ └── signup.ejs ├── 27_Creating_Discord_Bot_in_NodeJS ├── command.js ├── index.js ├── package-lock.json └── package.json ├── 28_Uploding_Files_with_NodeJS_and_Multer ├── Readme.md ├── index.js ├── package-lock.json ├── package.json ├── uploads │ └── 1712197245796-github (2).png └── views │ └── homepage.ejs ├── 29_Setting_Up_Project-NodeJS_Blogging_App ├── Readme.md ├── index.js ├── models │ └── user.js ├── package-lock.json ├── package.json ├── public │ └── images │ │ └── deafult.jpg ├── routes │ └── user.js └── views │ ├── home.ejs │ ├── partials │ ├── head.ejs │ ├── nav.ejs │ └── scripts.ejs │ ├── signin.ejs │ └── signup.ejs ├── 30_Setting_up_Authentication-NodeJS_Blogging_App ├── Readme.md ├── index.js ├── middlewares │ └── authentication.js ├── models │ ├── blog.js │ └── user.js ├── package-lock.json ├── package.json ├── public │ ├── images │ │ └── deafult.jpg │ └── uploads │ │ ├── 1712311193510-Screenshot (1).png │ │ └── 1712311768043-Screenshot (1).png ├── routes │ ├── blog.js │ └── user.js ├── services │ └── authentication.js └── views │ ├── addBlog.ejs │ ├── home.ejs │ ├── partials │ ├── head.ejs │ ├── nav.ejs │ └── scripts.ejs │ ├── signin.ejs │ └── signup.ejs ├── 31_Complete_Blog_App ├── Readme.md ├── index.js ├── middlewares │ └── authentication.js ├── models │ ├── blog.js │ ├── comments.js │ └── user.js ├── package-lock.json ├── package.json ├── public │ ├── images │ │ └── default.png │ └── uploads │ │ ├── 1712311193510-Screenshot (1).png │ │ ├── 1712311768043-Screenshot (1).png │ │ ├── 1712428496751-1_A7PQiIdB5buNa0mgq063Xg.png │ │ ├── 1712429054876-piyu.avif │ │ └── 1712429113684-fire.avif ├── routes │ ├── blog.js │ └── user.js ├── services │ └── authentication.js └── views │ ├── addBlog.ejs │ ├── blog.ejs │ ├── home.ejs │ ├── partials │ ├── head.ejs │ ├── nav.ejs │ └── scripts.ejs │ ├── signin.ejs │ └── signup.ejs ├── 32_Deploy_NodeJS_App_on_Cloud ├── .env ├── Readme.md ├── app.js ├── middlewares │ └── authentication.js ├── models │ ├── blog.js │ ├── comments.js │ └── user.js ├── package-lock.json ├── package.json ├── public │ ├── images │ │ └── default.png │ └── uploads │ │ ├── 1712311193510-Screenshot (1).png │ │ ├── 1712311768043-Screenshot (1).png │ │ ├── 1712428496751-1_A7PQiIdB5buNa0mgq063Xg.png │ │ ├── 1712429054876-piyu.avif │ │ └── 1712429113684-fire.avif ├── routes │ ├── blog.js │ └── user.js ├── services │ └── authentication.js └── views │ ├── addBlog.ejs │ ├── blog.ejs │ ├── home.ejs │ ├── partials │ ├── head.ejs │ ├── nav.ejs │ └── scripts.ejs │ ├── signin.ejs │ └── signup.ejs ├── 33_WebSocket ├── Readme.md ├── index.js ├── package-lock.json ├── package.json └── public │ └── index.html ├── 34_Streams ├── 20M.txt ├── Readme.md ├── index.js ├── package-lock.json └── package.json ├── 35_Scale_NodeJS_App_using_Cluster_module ├── Readme.md ├── app.js ├── cluster.js ├── package-lock.json └── package.json ├── 36_What_is_Nginx └── Readme.md ├── 37_Install_&_Setup_Nginx └── Readme.md ├── 42_GraphQL_NodeJS ├── Readme.md ├── client │ ├── .gitignore │ ├── README.md │ ├── package-lock.json │ ├── package.json │ ├── public │ │ ├── favicon.ico │ │ ├── index.html │ │ ├── logo192.png │ │ ├── logo512.png │ │ ├── manifest.json │ │ └── robots.txt │ └── src │ │ ├── App.css │ │ ├── App.js │ │ ├── App.test.js │ │ ├── index.css │ │ ├── index.js │ │ ├── logo.svg │ │ ├── reportWebVitals.js │ │ └── setupTests.js └── server │ ├── index.js │ ├── package-lock.json │ └── package.json ├── 43_Threads_App_GraphQL_Clone └── Readme.md └── Readme.md /.gitignore: -------------------------------------------------------------------------------- 1 | node_modules -------------------------------------------------------------------------------- /01_What_is_NodeJS/Learning.md: -------------------------------------------------------------------------------- 1 | Javascript code executes inside browser. 2 | 3 | Browser has javascript engine which executes the javascript code. 4 | 5 | Javascript Engine presents only inside Browser. 6 | 7 | Each broswer has different Javascript engines. 8 | 9 | ``` 10 | Chrome -> V8 Engine 11 | Fierfox -> Spider Monkey 12 | Safari -> Nitro 13 | ``` 14 | 15 | The most populor engine is V8 engine. 16 | 17 | A scientist Ryan Dahl taken the V8 engine and embedded with C++ code.And named this project as `NodeJS`. 18 | 19 | Now In NodeJS (Benefit) 20 | --- 21 | 22 | - You can run JS outside of the browser. 23 | - Javascript can talk to native machine beacause of C++. 24 | - You can create webservers in Javascript language. 25 | 26 | ## What is NodeJS? 27 | 28 | NodeJs is neither a framework or language . NodeJS is a Runtime Environment for javascript. 29 | 30 | Ex: 31 | ```javascript 32 | PS C:\Users\ayush> node 33 | Welcome to Node.js v20.10.0. 34 | Type ".help" for more information. 35 | > console.log("Hello"); 36 | Hello 37 | undefined 38 | > 2+2 39 | 4 40 | > 41 | 42 | ``` 43 | 44 | 45 | 46 | 47 | 48 | 49 | -------------------------------------------------------------------------------- /02_Node_JS_Installation/Learning.md: -------------------------------------------------------------------------------- 1 | # Steps to Install NodeJS 2 | 3 | 1. Go to official website `nodejs.org` 4 | 5 | 2. Select LTS Version of NodeJS.
6 | LTS - Long Term Support , Start with even number (Stable realese - can be used in production) 7 | 8 | Beta(Current) - Bugs , Unstability , start with odd number 9 | 10 | 3. Intall in your local computer and add the path `C:\Program Files\nodejs` to your environment variable. 11 | 12 | 4. Open Terminal and write command 13 | 14 | ```javascript 15 | PS C:\Users\ayush> node --version 16 | v20.10.0 17 | PS C:\Users\ayush> 18 | ``` 19 | 20 | 5. If giving this output then NodeJS Installed Succesfully. 21 | 22 | # What is npm ? 23 | 24 | NPM -> Node Package Manager. We can manage package through it. -------------------------------------------------------------------------------- /04_Modules_in_NodeJS/math.js: -------------------------------------------------------------------------------- 1 | 2 | function add(a , b){ 3 | return a + b 4 | } 5 | 6 | function sub(a , b){ 7 | return a - b; 8 | } 9 | 10 | // module.exports = add; 11 | // module.exports = sub ; // overiding the value 12 | 13 | // we can use object to export multiple values 14 | 15 | 16 | 17 | // multi exports 18 | module.exports = { 19 | add , 20 | sub, 21 | } 22 | 23 | 24 | //exporting anonymous function 25 | // exports.add = (a , b) => a + b; 26 | 27 | // exports.sub = ( a , b) => a - b; -------------------------------------------------------------------------------- /04_Modules_in_NodeJS/module.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Split your code into different files and folders. 3 | * All maths related function will be written in math.js 4 | * 5 | * To use the math.js file in other file 6 | * -------------------------------------- 7 | * use require -> const name = require('filename') 8 | * 9 | */ 10 | 11 | const buffer = require('buffer') // built in package 12 | 13 | const math = require('./math') 14 | 15 | //De-structuring -> we can directlly use add and sub function 16 | const {add , sub } = require('./math') 17 | 18 | console.log("Math Add value is : ",math.add(2 , 4)); 19 | console.log("Math Subtract value is : ",math.sub(2 , 4)); 20 | 21 | console.log("\nUsing destructured function \n") 22 | 23 | console.log("Math Add value is : ",add(2 , 4)); 24 | console.log("Math Subtract value is : ",sub(2 , 4)); 25 | 26 | -------------------------------------------------------------------------------- /04_Modules_in_NodeJS/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "4_modules_in_nodejs", 3 | "version": "1.0.0", 4 | "description": "", 5 | "main": "module.js", 6 | "scripts": { 7 | "test": "echo \"Error: no test specified\" && exit 1", 8 | "start":"node module.js" 9 | }, 10 | "author": "", 11 | "license": "ISC" 12 | } 13 | -------------------------------------------------------------------------------- /05_File_Handling_in_NodeJS/contacts.txt: -------------------------------------------------------------------------------- 1 | Ayush Kumar: +91 8238283828 2 | Jone Doe : +91 9222222222 -------------------------------------------------------------------------------- /05_File_Handling_in_NodeJS/file.js: -------------------------------------------------------------------------------- 1 | const fs = require('fs') 2 | 3 | //used this fs module to intract with files 4 | 5 | //creating a file (Synchronous call) 6 | // fs.writeFileSync("./test.txt" , 'Hey There'); 7 | 8 | //Async 9 | // fs.writeFile("./test.txt" , "Hello World", (err) => {}) 10 | 11 | 12 | //Reading the file 13 | 14 | // Sync.. -> returns the result 15 | // const result = fs.readFileSync("./contacts.txt" , "utf-8"); 16 | // console.log(result); 17 | 18 | //Async.. -> return nothing , we have to pass a callback 19 | // fs.readFile("./contacts.txt" , "utf-8" , (err , result)=>{ 20 | // if(err){ 21 | // console.log("Error",err); 22 | // }else{ 23 | // console.log(result); 24 | // } 25 | // }); 26 | 27 | 28 | // Appending the text 29 | // fs.appendFileSync("./test.txt" , "\nHey there I am appended"); 30 | 31 | 32 | // Copy the file 33 | // fs.cpSync("./test.txt" , "./copy.txt"); 34 | 35 | // Delete the file 36 | // fs.unlinkSync("./copy.txt"); 37 | 38 | // Cheking status of file 39 | // console.log(fs.statSync("./test.txt")); 40 | 41 | //making directory 42 | // fs.mkdirSync("my-docs"); 43 | fs.mkdirSync("my-docs/a/b" , { recursive:true}); 44 | 45 | 46 | -------------------------------------------------------------------------------- /05_File_Handling_in_NodeJS/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "5_file_handling_in_nodejs", 3 | "version": "1.0.0", 4 | "description": "", 5 | "main": "file.js", 6 | "scripts": { 7 | "test": "echo \"Error: no test specified\" && exit 1" 8 | }, 9 | "author": "", 10 | "license": "ISC" 11 | } 12 | -------------------------------------------------------------------------------- /05_File_Handling_in_NodeJS/test.txt: -------------------------------------------------------------------------------- 1 | Hello World27 2 | Hey there I am appended 3 | Hey there I am appended -------------------------------------------------------------------------------- /06_How_NodeJS_Works/blocking.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/unstoppableayush/Backend-NodeJS/1697f51cfce12404dee1153952f53eb2bb1e97d4/06_How_NodeJS_Works/blocking.png -------------------------------------------------------------------------------- /06_How_NodeJS_Works/contacts.txt: -------------------------------------------------------------------------------- 1 | Ayush Kumar: +91 8238283828 2 | Jone Doe : +91 9222222222 -------------------------------------------------------------------------------- /06_How_NodeJS_Works/file.js: -------------------------------------------------------------------------------- 1 | const fs = require('fs') 2 | const os = require('os') 3 | 4 | //gives the computer information 5 | console.log(os.cpus().length); 6 | 7 | 8 | // Sync.. Blocking .. 9 | 10 | console.log("1"); 11 | 12 | const result = fs.readFileSync('contacts.txt' , 'utf-8'); 13 | console.log(result); 14 | 15 | console.log("2"); 16 | 17 | 18 | // Async.. Non-Blocking 19 | 20 | console.log("\nNon-Blocking(Async) \n") 21 | 22 | console.log("1"); 23 | 24 | fs.readFile('contacts.txt' , 'utf-8' , (err , result)=>{ 25 | console.log(result); 26 | }) 27 | 28 | console.log("2"); 29 | console.log("3"); 30 | console.log("4"); -------------------------------------------------------------------------------- /06_How_NodeJS_Works/learning.md: -------------------------------------------------------------------------------- 1 | ``` 2 | Client ----------> Server 3 | Request (NodeJs) 4 | ``` 5 | 6 | Request made to server. Node js has event queue. 7 | 8 | Firstly requests are queued into event queue . 9 | 10 | Now even loop is a machine which always watches the event queue. 11 | 12 | If event loop get any request in event queue the select that request using fifo(first in first out) principle. 13 | 14 | Request can be of two types : 15 | 16 | 1. Blocking Operations (Sync.. task) 17 | 3. Non- Blockinng Operations (Async.. task) 18 | 19 | If the request has `non-blocking operation` then the server process it and sends the response back to the user. 20 | 21 | ![non-blocking operation in nodejs](./non-blocking.png) 22 | 23 | If the request has `blocking operation` then to resolve this request it goes to thread pool. 24 | 25 | Thread pool is a pool of threads . Threads act a worker which work for you . It is resposible for fuilful your blocking operation. If the works completes then it return the result . Then the respose is send back to the user . 26 | 27 | ![non-blocking operation in nodejs](./blocking.png) 28 | 29 | 30 | 31 | 32 | 33 | -------------------------------------------------------------------------------- /06_How_NodeJS_Works/non-blocking.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/unstoppableayush/Backend-NodeJS/1697f51cfce12404dee1153952f53eb2bb1e97d4/06_How_NodeJS_Works/non-blocking.png -------------------------------------------------------------------------------- /06_How_NodeJS_Works/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "5_file_handling_in_nodejs", 3 | "version": "1.0.0", 4 | "description": "", 5 | "main": "file.js", 6 | "scripts": { 7 | "test": "echo \"Error: no test specified\" && exit 1" 8 | }, 9 | "author": "", 10 | "license": "ISC" 11 | } 12 | -------------------------------------------------------------------------------- /07_Building_HTTP_Server/index.js: -------------------------------------------------------------------------------- 1 | const http = require("http"); 2 | const fs = require("fs"); 3 | 4 | const myServer = http.createServer((req , res)=>{ 5 | 6 | const log = `${Date.now()} : ${req.url} : New Request Recieved \n`; 7 | fs.appendFile('log.txt' , log , (err , data)=>{ 8 | 9 | switch(req.url){ 10 | case '/' : res.end("Home Page"); 11 | break; 12 | 13 | case '/about' : res.end("I am Ayush"); 14 | break; 15 | 16 | default: 17 | res.end("404 Not Found") 18 | 19 | } 20 | 21 | 22 | }) 23 | 24 | 25 | // console.log(req.headers) 26 | // console.log(req) 27 | 28 | 29 | }); 30 | 31 | const PORT = 8000; 32 | myServer.listen(8000, ()=>{ 33 | console.log(`Server started at port no ${PORT} `); 34 | }) 35 | 36 | -------------------------------------------------------------------------------- /07_Building_HTTP_Server/log.txt: -------------------------------------------------------------------------------- 1 | 1709126389288 : New Request Recieved 2 | 1709126389582 : New Request Recieved 3 | 1709126402207 : New Request Recieved 4 | 1709126402351 : New Request Recieved 5 | 1709126410765 : New Request Recieved 6 | 1709126410941 : New Request Recieved 7 | 1709126501780 : New Request Recieved 8 | 1709126501991 : New Request Recieved 9 | 1709126516561 : / : New Request Recieved 10 | 1709126516662 : /favicon.ico : New Request Recieved 11 | 1709126528727 : /about : New Request Recieved 12 | 1709126528831 : /favicon.ico : New Request Recieved 13 | 1709126559937 : /contactus : New Request Recieved 14 | 1709126560124 : /favicon.ico : New Request Recieved 15 | 1709126684112 : /contactus : New Request Recieved 16 | 1709126684220 : /favicon.ico : New Request Recieved 17 | 1709126687361 : / : New Request Recieved 18 | 1709126687456 : /favicon.ico : New Request Recieved 19 | 1709126693949 : /about : New Request Recieved 20 | 1709126694048 : /favicon.ico : New Request Recieved 21 | -------------------------------------------------------------------------------- /07_Building_HTTP_Server/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "7_building_http_server", 3 | "version": "1.0.0", 4 | "description": "", 5 | "main": "index.js", 6 | "scripts": { 7 | "start": "node index", 8 | "test": "echo \"Error: no test specified\" && exit 1" 9 | }, 10 | "author": "", 11 | "license": "ISC" 12 | } 13 | -------------------------------------------------------------------------------- /08_Handling_URL/Learning.md: -------------------------------------------------------------------------------- 1 | # URL 2 | Uniform Resource Locator 3 | 4 | ``` 5 | https:// www.ayush.dev/ 6 | -------- -------------- 7 | Protocol Domain - User friendly name 8 | of IP Address of My Server 9 | 10 | dev/ -> Path 11 | ayush.dev/project/1 -> Nested Path 12 | 13 | ayush.dev/about?userID=1&a=2 -> Query parameter 14 | 15 | ``` 16 | 17 | Protocol: Set of rules that tells browser how to communicate to the browser. 18 | 19 | https -> Hypertext Transfer Protocol Secure 20 | 21 | -------------------------------------------------------------------------------- /08_Handling_URL/index.js: -------------------------------------------------------------------------------- 1 | const http = require("http"); 2 | const fs = require("fs"); 3 | const url = require("url"); 4 | 5 | const myServer = http.createServer((req , res)=>{ 6 | 7 | if(req.url === '/favicon.ico') return res.end(); 8 | 9 | 10 | const log = `${Date.now()} : ${req.url} : New Request Recieved \n`; 11 | const myUrl = url.parse(req.url , true); 12 | console.log(myUrl); 13 | 14 | fs.appendFile('log.txt' , log , (err , data)=>{ 15 | 16 | switch(myUrl.pathname){ 17 | case '/' : res.end("Home Page"); 18 | break; 19 | 20 | case '/about' : 21 | //query parameter 22 | const username = myUrl.query.myname ; 23 | console.log(username) 24 | res.end(`Hii, ${username}`); 25 | break; 26 | 27 | case "/search": 28 | const search = myUrl.query.search_query; 29 | console.log(search) 30 | res.end("Here are your result for "+search); 31 | break; 32 | 33 | default: 34 | res.end("404 Not Found") 35 | 36 | } 37 | 38 | 39 | }) 40 | 41 | 42 | // console.log(req.headers) 43 | // console.log(req) 44 | 45 | 46 | }); 47 | 48 | const PORT = 8000; 49 | myServer.listen(8000, ()=>{ 50 | console.log(`Server started at port no ${PORT} `); 51 | }) 52 | 53 | -------------------------------------------------------------------------------- /08_Handling_URL/log.txt: -------------------------------------------------------------------------------- 1 | 1709129047044 : / : New Request Recieved 2 | 1709129073528 : /about : New Request Recieved 3 | 1709129148969 : /about? : New Request Recieved 4 | 1709129174894 : /about?myname=Ayush : New Request Recieved 5 | 1709129456962 : /about?myname=Ayush : New Request Recieved 6 | 1709129715248 : /about?myname=Ayush : New Request Recieved 7 | 1709129744591 : /about?myname=Ayush&userid=1 : New Request Recieved 8 | 1709129821573 : /about?myname=Ayush&userid=1 : New Request Recieved 9 | 1709129828388 : /about?myname=Ayush : New Request Recieved 10 | 1709129853737 : /about?myname=Ayush : New Request Recieved 11 | 1709129900258 : /about : New Request Recieved 12 | 1709129906871 : /about?myname=Ayush : New Request Recieved 13 | 1709129911244 : /about/?myname=Ayush : New Request Recieved 14 | 1709129975789 : /about/?myname=Ayush : New Request Recieved 15 | 1709130026368 : / : New Request Recieved 16 | 1709130035112 : /about : New Request Recieved 17 | 1709130048246 : /about?myname=Ayush : New Request Recieved 18 | 1709130055907 : /about?myname=Ayush : New Request Recieved 19 | 1709130141940 : /about?myname=Ayush : New Request Recieved 20 | 1709130151391 : /about : New Request Recieved 21 | 1709130162145 : /about?myname=Ayush : New Request Recieved 22 | 1709130290638 : / : New Request Recieved 23 | 1709130306635 : /search_query=ayush : New Request Recieved 24 | 1709130336662 : /search/search_query=ayush : New Request Recieved 25 | 1709130441084 : /search/search_query=ayush : New Request Recieved 26 | 1709130450412 : / : New Request Recieved 27 | 1709130461413 : /search?search_query=ayush : New Request Recieved 28 | 1709130679041 : /search?search_query=ayush : New Request Recieved 29 | 1709130718820 : /search?search_query=ayush : New Request Recieved 30 | 1709130841622 : /search?search_query=ayush : New Request Recieved 31 | 1709130849090 : /search?search_query=ayush : New Request Recieved 32 | 1709130861890 : /search? : New Request Recieved 33 | 1709130864537 : /search? : New Request Recieved 34 | 1709130867377 : /search : New Request Recieved 35 | 1709130881093 : /search/search_query=Ayushasn : New Request Recieved 36 | -------------------------------------------------------------------------------- /08_Handling_URL/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "7_building_http_server", 3 | "version": "1.0.0", 4 | "description": "", 5 | "main": "index.js", 6 | "scripts": { 7 | "start": "node index", 8 | "test": "echo \"Error: no test specified\" && exit 1" 9 | }, 10 | "author": "", 11 | "license": "ISC", 12 | "dependencies": { 13 | "url": "^0.11.3" 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /09_HTTP_Methods/Learnings.md: -------------------------------------------------------------------------------- 1 | # HTTP Methods 2 | ``` 3 | GET -> When you want to get some data from the server. 4 | 5 | POST -> When you want to send and mutate some data in server. 6 | 7 | PUT 8 | PATCH 9 | DELETE 10 | ``` -------------------------------------------------------------------------------- /09_HTTP_Methods/index.js: -------------------------------------------------------------------------------- 1 | const http = require("http"); 2 | const fs = require("fs"); 3 | const url = require("url"); 4 | 5 | const myServer = http.createServer((req , res)=>{ 6 | 7 | if(req.url === '/favicon.ico') return res.end(); 8 | 9 | 10 | const log = `${Date.now()} : ${req.url} : New Request Recieved \n`; 11 | const myUrl = url.parse(req.url , true); 12 | console.log(myUrl); 13 | 14 | fs.appendFile('log.txt' , log , (err , data)=>{ 15 | 16 | switch(myUrl.pathname){ 17 | 18 | case '/' : 19 | 20 | if(req.method == 'GET') res.end("Home Page"); 21 | break; 22 | 23 | case '/about' : 24 | //query parameter 25 | const username = myUrl.query.myname ; 26 | console.log(username) 27 | res.end(`Hii, ${username}`); 28 | break; 29 | 30 | case "/search": 31 | const search = myUrl.query.search_query; 32 | console.log(search) 33 | res.end("Here are your result for "+search); 34 | break; 35 | 36 | case '/signup': 37 | 38 | if(req.method == 'GET') res.end("This is a signup From"); 39 | else if(req.method == "POST"){ 40 | //DB Query 41 | res.end("Success"); 42 | } 43 | break; 44 | default: 45 | res.end("404 Not Found") 46 | 47 | } 48 | 49 | 50 | }) 51 | 52 | 53 | // console.log(req.headers) 54 | // console.log(req) 55 | 56 | 57 | }); 58 | 59 | const PORT = 8000; 60 | myServer.listen(8000, ()=>{ 61 | console.log(`Server started at port no ${PORT} `); 62 | }) 63 | 64 | -------------------------------------------------------------------------------- /09_HTTP_Methods/log.txt: -------------------------------------------------------------------------------- 1 | 1709226120135 : / : New Request Recieved 2 | 1709226126979 : /signup : New Request Recieved 3 | 1709226163929 : /signup : New Request Recieved 4 | 1709226164361 : /signup : New Request Recieved 5 | -------------------------------------------------------------------------------- /09_HTTP_Methods/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "7_building_http_server", 3 | "version": "1.0.0", 4 | "description": "", 5 | "main": "index.js", 6 | "scripts": { 7 | "start": "node index", 8 | "test": "echo \"Error: no test specified\" && exit 1" 9 | }, 10 | "author": "", 11 | "license": "ISC", 12 | "dependencies": { 13 | "url": "^0.11.3" 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /10_Getting_Started_with_Express_and_Nodejs/index.js: -------------------------------------------------------------------------------- 1 | const express = require("express") 2 | 3 | const app = express(); 4 | 5 | app.get('/',(req , res)=>{ 6 | return res.send("Hello from Home Page") 7 | }); 8 | 9 | app.get('/about' , (req , res)=>{ 10 | return res.send(`Hello ${req.query.name}`) 11 | }) 12 | 13 | const PORT = 8000; 14 | app.listen(8000, ()=>{ 15 | console.log(`Server started at port no ${PORT} `); 16 | }) 17 | 18 | -------------------------------------------------------------------------------- /10_Getting_Started_with_Express_and_Nodejs/log.txt: -------------------------------------------------------------------------------- 1 | 1709227219573 : / : New Request Recieved 2 | -------------------------------------------------------------------------------- /10_Getting_Started_with_Express_and_Nodejs/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "7_building_http_server", 3 | "version": "1.0.0", 4 | "description": "", 5 | "main": "index.js", 6 | "scripts": { 7 | "start": "node index", 8 | "test": "echo \"Error: no test specified\" && exit 1" 9 | }, 10 | "author": "", 11 | "license": "ISC", 12 | "dependencies": { 13 | "express": "^4.18.3" 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /11_How_Versioning_Works_in_NodeJS/Learnings.md: -------------------------------------------------------------------------------- 1 | # Version 2 | 3 | 4.18.2 4 | 5 | 1st Part -> 4 6 | 2nd Part -> 18 7 | 3rd Part -> 2 8 | 9 | 3rd part(Last Part) - Miner Fixes (Optional) 10 | Latest -> 4.18.3 11 | 12 | 2nd Part - Recommended Bug Fix (Security) 13 | Latest -> 4.19.1 14 | 15 | 3rd Part -> Major Realese -> Major / Breaking Update 16 | Latest -> 5.0.1 17 | 18 | --- 19 | 20 | "express": "^4.18.3" 21 | 22 | ^4.18.3 | ^4.18.3 -> 5.0.0 23 | 24 | ^4.17.9 25 | ^4.18.1 26 | ^4.18.2 27 | ^4.18.3 28 | .. 29 | ^5.1.1 ❌ 30 | 31 | --- 32 | 33 | ~4.18.1 34 | ~4.18.2 35 | ~4.18.3 36 | ~4.18.4 37 | 38 | ~4.19.1 ❌ 39 | -------------------------------------------------------------------------------- /11_How_Versioning_Works_in_NodeJS/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "11_how_versioning_works_in_nodejs", 3 | "version": "1.0.0", 4 | "description": "", 5 | "main": "index.js", 6 | "scripts": { 7 | "test": "echo \"Error: no test specified\" && exit 1" 8 | }, 9 | "author": "", 10 | "license": "ISC", 11 | "dependencies": { 12 | "express": "^4.18.3" 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /12_What_is_REST_API/1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/unstoppableayush/Backend-NodeJS/1697f51cfce12404dee1153952f53eb2bb1e97d4/12_What_is_REST_API/1.png -------------------------------------------------------------------------------- /12_What_is_REST_API/2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/unstoppableayush/Backend-NodeJS/1697f51cfce12404dee1153952f53eb2bb1e97d4/12_What_is_REST_API/2.png -------------------------------------------------------------------------------- /12_What_is_REST_API/3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/unstoppableayush/Backend-NodeJS/1697f51cfce12404dee1153952f53eb2bb1e97d4/12_What_is_REST_API/3.png -------------------------------------------------------------------------------- /12_What_is_REST_API/4.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/unstoppableayush/Backend-NodeJS/1697f51cfce12404dee1153952f53eb2bb1e97d4/12_What_is_REST_API/4.png -------------------------------------------------------------------------------- /12_What_is_REST_API/Learnings.md: -------------------------------------------------------------------------------- 1 | # Restfull API Rules 2 | 3 | 1. Works on server client architecture. 4 | 5 |
6 | 7 | ![Clinet server architecture](./1.png) 8 | 9 | 2. Always Respect All Http methods. 10 | Get , Post , Put , Delete 11 | 12 | Get /user - user data read kro and return kro 13 | 14 | Post /user - handle new user creation 15 | 16 | Pathch /user - Update the user 17 | 18 |
19 | 20 | ![http methods rule](./2.png) 21 | ![http methods rule](./3.png) 22 | ![http methods rule](./4.png) 23 | 24 | 25 | 26 | -------------------------------------------------------------------------------- /13_Building_REST_API_using_Node_and_Express/index.js: -------------------------------------------------------------------------------- 1 | const express = require("express"); 2 | const users = require("./MOCK_DATA.json") 3 | 4 | const app = express(); 5 | const PORT = 8000; 6 | 7 | //Routes 8 | app.get('/users', (req, res)=>{ 9 | const html = ` 10 |