API - nothing but a response.
Download NodeJs Enviornment
Computer <-express-> Server
npm init
"start": "node index.js" export default defineConfig({
server:{
proxy: {
'/api' :'http://localhost:3000'
},
},
plugins: [react()],
})
append the url http://localhost:3000 before /api whenever server get url start from /api
.gitkeep standard procedure to track Empty folder..gitignore used to not track and push the files..env.sample to give env variables to others.npm i -D nodemon )src directory
controllers - Functionality.db - Database connection.middlewares - Code run in between.models - Database schemaroutes - Handle different routesutils - Utility (File Upload , Mailing , Tokens)prettier - To maintain formatting in a team..prettierrc file to define formatting..prettierignore file to ignore the formatting in defined files.dotenv , mongoose , express packages.Two important points about database connectivity:
When connecting to databases, handling potential data-not-found scenarios is essential. Employ try/catch blocks or promises to manage errors or we can also use promises.
Database operations involve latency, and traditional synchronous code can lead to blocking, where the program waits for the database query to complete before moving on. So, we should async/await which allows for non-blocking execution, enabling the program to continue with other tasks while waiting for the database response.
Used two approach to connect the database - 1. In Index File, 2. In Seprate DB file
"scripts": {
"start": "node --env-file=.env src/index.js",
"dev": "nodemon --env-file=.env src/index.js"
}
connectionInstancecookie-parser & corscors middleware.app.use(express.json())express.static("public") used this middleware to staticlly use the files. (images, pdf, etc)utils Folder for handling async operation and Api Error.user model & video modelmongoose-aggregate-paginate-v2 package for Video Schemabcrypt package to hash password.JWT package to create tokens.JWT is a bearer token.generateAccessToken & generateRefreshToken.cloudinary and multer to upload files.diskstorage.metadata - Key-value send along with request & response.x-prefix -> 2012(x-deprecated)
Request Headers -> from Client
Response Headers -> from Server
Representation Headers -> encoding / compression
Payload Headers -> data
Accept : application/json
User-Agent (Request from which application)
Authorization (Bearer token)
Content-Type (Images, Pdf, etc)
Cookie
Cache-Control (Expiry of Data)
Access-Control-Allow-Origin
Access-Control-Allow-Credentials
Access-Control-Allow-Methpd
Cross-Design-Embeddedr-Policy
Cross-Design-Opener-Policy
Content-Security-Policy
X-XSS-Protection
Basic set of operations that can be used to interact with server.
HTTP Status Code :
1XX - Informational
2XX - Success
3XX - Redirection
4XX - Client Error
5XX - Server Error
100 - Continue 400 - Bad Request
102 - Processsing 401 - Unauthorized
200 - Ok 402 - Payement required
201 - Created 404 - Not Found
202 - Accepted 500 - Internal ServerError
307 - Temporary redirect 504 - Gateway timeout
308 - Permanent redirect
req.files , existedUserApiResponse of created user.await.req.files.collection and variable in Postman.login and logout.refreshAccessTokenchangeCurrentPassword function in user controller.getCurrentUser function to get current user info.updateAccountDetailsto update fullname and email.updateUserAvatar controller to update the user profile.updateCoverImage controller to update cover image of user.Subscribers , ChannelSubscribers & Channel.a subscribes channel CAC then a new document will be created. It will contain Channel -> CAC & Subscribers -> a. It will continues for others users.Subscribers - No. of documents where channel == CACChannel - Extract channel name and No. of documents where subscriber == c (subscribed channel)getUserChannelProfile contoller.getWatchHistory controller. Enviornment Variables -> Dependency (Packages) -> Database Connection -> Setting Path (index.js) -> Routing & Controller , Api Versioning -> Models -> Model Hooks -> Tokens -> Controllers (User) -> DB Query -> CRUD Operation -> Middlewares -> File Management (During Uplading) -> Aggregation Pipelines -> MongoDB Operators
comment.model.jsplaylist.model.jstweet.model.jslike.model.js