- High-level programming language
- Interpreted programming language
- Built on C++
- Dynamically typed programming language
- Used to build interactive web pages
- ECMA Script (ES6 2015) Standardization of JS
- NodeJS, Electron.js, React Native, Tensorflow.js
- It is a JavaScript runtime.
- Runtime: A program that runs another program
- Runs JS in local machine
- Build on C++
- Built on top of Google Chrome V8 engine
- Used for: API, micro-services, real time app, JSON based API
- Single threaded
- Non-blocking operation
- Event driven
- It is NodeJs API/backend framework, used to build API (Application program interface).
- It simplifies the HTTP module of Node.js
- Minimalist, unopinionated framework
- REST API
- API format
- JSON (we will use this)
- XML
- REST (Representational state transfer) API
- JSON => JavaScript Object : JSON.parse()
- JavaScript Object => JSON : JSON.stringify()
- Non-relational database
- Data are stored in collections & documents
- Database: Main container, where all collection of data are stored.
- Collection: Equivalent to table of relational database
- Document: Equivalent to Row
- Field: Equivalent to Column
- Locally: MongoDB Compass (shell included)
- Cloud: MongoDB Atlas
- Download and install MongoDB (https://www.mongodb.com/try/download/community)[https://www.mongodb.com/try/download/community]
- Download and install MongoDB Compass (https://www.mongodb.com/try/download/compass)[https://www.mongodb.com/try/download/compass]
Note: In some cases, try to add the mongodb path in environment variables (system)
- Run MongoDB Compass
- Setup a new connection (mongodb://localhost:27017)[mongodb://localhost:27017]
- show dbs: Show database list
- use : Use database (create database if not exists)
- show collections: Show list of collections (table)
- insertOne
- db..insertOne()
- for e.g: db.users.insertOne({name:"Ram", email: "ram@gmail.com"})
- insertMany
- db..insertMany()
- for e.g: db.users.insertOne([{name:"Ram", email: "ram@gmail.com"}, {name:"sita", email: "sita@gmail.com"}])
- find
- db..find()
- for e.g: db.products.find()
- for e.g: db.products.find({name:"iphone"})
- findOne
- db..findOne({})
- for e.g: db.products.findOne({name:"iphone"})
- countDocuments
- db.products.countDocuments()
- updateOne
- db..updateOne({find}, {$set: {key: value} })
- deleteOne
- db..deleteOne({find})
- $eq: db.users.find({name: {$eq: "Ram"} })
- $ne: db.users.find({name: {$ne: "Ram"} })
- $gt/$gte: db.users.find({age: {$gt: 20} })
- $lt/$lte: db.users.find({age: {$lt: 20} })
- $and: db.users.find({$and : [ {age: {$gt: 20} }, {name: {$eq: "Ram"} } ] })
- $or: db.users.find({$or : [ {age: {$gt: 20} }, {name: {$eq: "Ram"} } ] })
- sort: db.users.find().sort({name: 1}) 1: ASC, -1: DESC
- limit: db.users.find().limit(10)
- skip: db.users.find().skip(5)
- ODM of MongoDB for Node.js
- Create Schema/ Validate Schema
- Create models using schema
- Middleware
- Relationships
-
Encryption: Converting readable text to cipher text (unreadable)
-
for e.g: hello => 31586621468vq146qww1
-
Decryption: Converting cipher text to readable
-
for e.g: 31586621468vq146qww1 => hello
- Symmetric: Same key is used for encryption and decryption
- Asymmetric: Different keys are used in encryption and decryption, Public key/Private Key
- One way encryption
- Convert readable text to cipher but not back to readable
- Hashing of a text always returns same cipher
-
Adding random characters in hash value
-
123456 => arfgsdfuiqwerasopdfa45ydpsdf
-
123456 => as12345idfqweuiorasdfa0sdfgd
- Authentication: Who you are? Logged in user
- Authorization: What you can do? User role
- Self verified
- Used for auth
- Tamper proof
- Header
- Payload
- Signature
- Cookie storage
- Size: 4KB
- Storage: Server & Browser
- Expiry: Cookie expiry
- Local storage
- Size: 5MB
- Storage: Only Browser
- Expiry: Never expires
- Session storage
- Size: 5MB
- Storage: Only Browser
- Expiry: On Tab close
- Login/Register success
- Generate token (JWT)
- Store token: Cookie, Session storage, Local storage
- Append token in every request to handle auth
- Verify the token and authenticate/authorize user
- Function that lies between request and response.
Browser ------------ Request -----------> Server Middleware Server ------------- Response -----------> Browser
- Function that has the access of both request and response object
- It has additional functionality to go to next() middleware call
- Logging
- Authentication & Authorization
- Request & Response object modification
- Error handling, data validation
- USER -> Order create
- MERCHANT -> Product create/update/delete
- ADMIN -> Product mngt, User mngt, Order mngt
-
Check/Verify whether the input data is valid or not
-
For e.g. name (string), age (number), isActive (boolean)
-
Validation -> API (Most important), Frontend, Database (optional)
- GET : Used to fetch/retrieve data, No request body (READ)
- POST : Used to create data, uses request body to send data to API (CREATE)
- PUT : Used to update data, uses request body to send data to API (UPDATE)
- DELETE : Used to delete data (DELETE)
- PATCH : Used to partially update data
POST /product JSON(data) -> Validate data -> Store in Database
- 1xx - Informational (rarely used)
- 2xx - Success
- 200: OK
- 201: Created
- 204: No content (delete)
- 3xx - Redirect (rarely used)
- 301: Moved permanently
- 304: Not modified (used for caching)
- 4xx - Client Error
- 400: Bad request (invalid input)
- 401: Unauthorized (not logged in user, no token/expired token)
- 403: Forbidden (logged in but not allowed)
- 404: Not found
- 405: Method not allowed
- 409: Conflict (duplicate email, phone)
- 422: Unprocessable entity (validation error)
- 5xx - Server Error
- 500: Internal server error
- 502: Bad gateway (invalid response from another service)
- 503: Service unavailable (temporary)
- 504: Timeout
- Use templates, from google docs, canva
- Your personal info like, name, email, address, phone along with github & linkedin account
- Your short bio, summary
- Experiences (Internship)
- Avoid using paragraph
- Add technical skills based on job, for e.g use MERN stack related tech for MERN stack developer
- Highest level of education
- API Layer
a. Routes
- Handle the routes/endpoints b. Controllers
- Handle requests and responses c. Middlewares
- Handle requests and responses
- Logging, Auth
- Business Logic Layer a. Services
- Data Logic Layer a. Models
- Database Layer
- Always format your code (Use prettier code formatter)
- Use proper spacing and line spacing.
- Always use camelCase while naming your files and folders in JS (helloWorld)
- Always use camelCase while naming your function & variables in JS (createUser)
- File, variable names must be NOUN
- Function & methods names must be VERB
- Also check singular & plural case e.g (getUserById, getUsers)
- Avoid using number while naming variable, function, file (test1 ❌, testOne ✅)
- Add a line above
returnstatement - If you have list of codes, arrange in ASC order
ctrl + shift + s
- Model
- Service
- Controller
- Routes
- Validation Schema (libs)
- user (customer)
- orderItems
- product
- quantity
- status: pending, confirmed, shipped, delivered, cancelled
- shippingAddress
- totalPrice
- orderNumber
- payment
- File data -> Send as FormData
- Use multer package to handle formdata
- Upload to cloudinary
- Receive the file url from uploaded file
- Store the URL in database
- Check from root app.js file
- Check in the routes file. for e.g
product.route.js - Check in the controller file. for e.g
product.controller.js - Check in the service file. for e.g
product.service.js - Check imported files/functions
-
User requests for forgot password
-
User inputs the email address
-
Using the email address, find the user and create a reset password link & token
-
Send the reset password link to that email
-
User clicks on the reset password link from the received email.
-
User inputs the new password, along with the token (reset password link)
-
Verify the user & token
-
Update the password.
- Performing operation in multiple documents (table)
- Filtering in multiple documents
- Data formatting
- $match => Filtering
- $lookup => LEFT JOINS
- $unwind => INNER JOIN
- $project => Data formatting
- $group => complex grouped operations
=========================================================================================
- Variables
- Data types
- Operators (arithmetic, logical, relational)
- Conditional Statement (if, else, switch, ternary operator)
- Loop (for, while)
- Function
- EcmaScript (Template literals, spread operator, destructuring, arrow function)
- Array methods (map, reduce, sort, filter, find, includes, every, some)
- NodeJS
- CommonJS/ES modules
- File system
- HTTP
- Event
- Path
- URL
- HTTP methods, HTTP status codes (API)
- Callbacks, Promises, async/await
- Express
- Environment variables (secrets, config)
- Architecture
- Postman
- Semantics
- Filter queries, pagination
- Orders management
- Payment (khalti)
- File upload (Cloudinary, multer)
- Debugging
- Forgot password, reset password
- Email send
- User management
- Mongodb Aggregation
- Deployment
- MongoDB Atlas
- AI integration
- Template engine
- Refresh token (front end)
- Pay via stripe
- JS
Backend 2. Node 3. Express 4. MongoDB
Frontend
- DOM manipulation
- React
- Next.js
- Always create a new branch from
mainbranch - Always format your code, use prettier code formatter