MEAN Stack Development 2 — Questions and Answers
Question 1: In a MEAN stack app, which Angular decorator is used to define a component's metadata such as its template and selector?
- @NgModule
- @Component (Correct answer)
- @Injectable
- @Directive
Correct answer: @Component
@Component decorator marks a class as an Angular component and provides configuration metadata including selector, template, and styles.
Question 2: Which MongoDB operator is used to update only specific fields in a document without replacing the entire document?
- $replace
- $set (Correct answer)
- $update
- $merge
Correct answer: $set
The $set operator updates only the specified fields in a document, leaving all other fields unchanged.
Question 3: What is the purpose of Express.js middleware's `next()` function?
- Terminates the request
- Sends a response to the client
- Passes control to the next middleware function (Correct answer)
- Connects to MongoDB
Correct answer: Passes control to the next middleware function
Calling next() passes control to the next middleware in the stack; without it, the request-response cycle would hang.
Question 4: In Node.js, what does the `EventEmitter` class primarily enable?
- Database connection pooling
- File system synchronization
- Asynchronous event-driven communication between objects (Correct answer)
- HTTP request routing
Correct answer: Asynchronous event-driven communication between objects
EventEmitter allows objects to emit named events and register listener functions that respond to those events asynchronously.
Question 5: Which of the following correctly describes a Mongoose 'virtual' field?
- A field stored in MongoDB but never retrieved
- A computed property that is not persisted to the database (Correct answer)
- An encrypted field requiring special access
- A field that maps to a different collection
Correct answer: A computed property that is not persisted to the database
Mongoose virtuals are properties computed from existing document data at runtime and are not saved to MongoDB.
Question 6: What Angular feature allows you to share data and logic across multiple unrelated components?
- Pipes
- Directives
- Services with dependency injection (Correct answer)
- Template reference variables
Correct answer: Services with dependency injection
Angular Services combined with dependency injection provide a singleton pattern for sharing state and business logic across components.
Question 7: In the MEAN stack, which HTTP method is conventionally used to partially update an existing resource?
- POST
- PUT
- PATCH (Correct answer)
- DELETE
Correct answer: PATCH
PATCH is used for partial updates to an existing resource, while PUT replaces the entire resource.
In a MEAN stack app, which Angular decorator is used to define a component's metadata such as its template and selector?