-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathNode.txt
More file actions
181 lines (91 loc) · 4.14 KB
/
Node.txt
File metadata and controls
181 lines (91 loc) · 4.14 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
1. What is Node.js?
Node.js is a JavaScript runtime that allows us to run JavaScript outside the browser, mainly on the server.
2. Is Node.js a language or framework?
No. Node.js is a runtime environment, not a language or framework.
3. Why is Node.js fast?
Because it uses non-blocking I/O and an event-driven architecture.
4. What is the event loop?
The event loop handles asynchronous operations and allows Node.js to execute tasks without blocking the main thread.
5. What are Node core modules?
Built-in modules like fs, http, path, os that don’t require installation.
6. What is npm?
npm is a package manager used to install and manage Node.js libraries.
7. What is Express.js?
Express.js is a Node.js framework used to build web servers and REST APIs easily.
8. Why do we use Express instead of http module?
Express reduces boilerplate code and provides easy routing, middleware, and request handling.
9. What is middleware?
Middleware is a function that runs between request and response.
10. Why do we use express.json()?
To read JSON data sent from the client in req.body.
11. Difference between GET and POST?
GET is used to fetch data, POST is used to send data to the server.
12. What is REST API?
A REST API follows standard HTTP methods like GET, POST, PUT, DELETE to perform CRUD operations.
13. Why do we separate routes and controllers?
To keep code clean, readable, and easy to maintain.
14. What is the role of routes?
Routes define the API URLs and HTTP methods.
15. What is the role of controllers?
Controllers contain the business logic of the application.
16. Difference between app.js and server.js?
app.js configures middleware and routes, server.js starts the server.
17. What is centralized error handling?
Handling all errors in one middleware instead of repeating try-catch everywhere.
18. What is MongoDB?
MongoDB is a NoSQL database that stores data in JSON-like documents.
19. Difference between SQL and MongoDB?
SQL uses tables and rows, MongoDB uses collections and documents.
20. What is Mongoose?
Mongoose is an ODM library used to connect Node.js with MongoDB.
21. What is a Schema?
Schema defines the structure and rules of a document.
22. What is a Model?
A Model is used to interact with a MongoDB collection.
23. Why do we use async/await with MongoDB?
Database operations are asynchronous and take time.
24. Why is backend validation important?
Because frontend validation can be bypassed.
25. What is required in schema?
It ensures that a field must be provided before saving data.
26. What is unique?
It prevents duplicate values in a field.
27. What is Mongoose middleware?
Functions that run automatically before or after database operations.
28. Difference between save() and findByIdAndUpdate()?
save() triggers middleware, findByIdAndUpdate() does not by default.
29. Why use runValidators: true?
To apply schema validation during update operations.
30. What is authentication?
Process of verifying user identity.
31. Why do we hash passwords?
To protect passwords even if the database is hacked.
32. What is bcrypt?
A library used to hash and compare passwords securely.
33. What is JWT?
JSON Web Token used for secure user authentication.
34. Why JWT is stateless?
It does not store session data on the server.
35. Why use select:false for password?
To prevent password from being returned in API responses.
36. What is authorization?
Determining what actions a user is allowed to perform.
37. Difference between 401 and 403?
401 = not logged in
403 = logged in but not allowed
38. What is RBAC?
Role-Based Access Control.
39. Why role check should be backend side?
Frontend checks can be easily bypassed.
40. Why use middleware for authorization?
To reuse role logic and keep controllers clean.
41. What is CORS?
Browser security mechanism that restricts cross-origin requests.
42. Why CORS error occurs?
Frontend and backend run on different origins.
43. How do you fix CORS?
By enabling CORS middleware in backend.
44. Why use Axios instead of fetch?
Axios has simpler syntax and supports interceptors.
45. What is interceptor?
A function that runs before sending requests or receiving responses.