MEAN Stack Development MCQ 4 — Questions and Answers
Question 1: Which Angular RxJS operator should you use to cancel a previous HTTP request when a new search term is typed quickly?
- mergeMap
- concatMap
- switchMap (Correct answer)
- exhaustMap
Correct answer: switchMap
switchMap cancels the previous inner observable and switches to a new one, making it ideal for typeahead searches to avoid stale responses.
Question 2: What does the `--save-dev` flag do when used with `npm install`?
- Saves the package as a production dependency in package.json
- Saves the package as a development-only dependency in devDependencies (Correct answer)
- Installs the package globally on the system
- Saves the package without updating package-lock.json
Correct answer: Saves the package as a development-only dependency in devDependencies
The --save-dev flag adds the package to devDependencies in package.json, indicating it's only needed during development and testing, not in production.
Question 3: In MongoDB, what is the difference between `findOne()` and `find().limit(1)`?
- findOne() returns a document object while find().limit(1) returns a cursor (Correct answer)
- find().limit(1) is faster because it uses an index
- findOne() always sorts results before returning
- There is no practical difference between the two
Correct answer: findOne() returns a document object while find().limit(1) returns a cursor
findOne() directly returns a single document (or null), while find().limit(1) returns a cursor that must be iterated to access the document.
Question 4: What is Angular's `HttpInterceptor` primarily used for?
- To cache HTTP responses in localStorage automatically
- To intercept and transform HTTP requests and responses globally (Correct answer)
- To retry failed HTTP requests with exponential backoff
- To validate HTTP request bodies before sending
Correct answer: To intercept and transform HTTP requests and responses globally
HttpInterceptor allows you to intercept outgoing requests and incoming responses globally, commonly used for adding auth tokens, logging, or error handling.
Question 5: Which Node.js built-in module provides an interface for working with the operating system?
- sys
- process
- os (Correct answer)
- system
Correct answer: os
The os module provides operating system-related utility methods and properties like platform, CPU info, free memory, and home directory.
Question 6: What is the purpose of the `forRoot()` and `forChild()` patterns in Angular NgModule configuration?
- forRoot() is for root components, forChild() is for child components
- forRoot() registers providers once app-wide, forChild() imports features without re-registering services (Correct answer)
- forRoot() is used in lazy modules, forChild() in eagerly loaded modules
- forRoot() configures routing, forChild() configures HTTP
Correct answer: forRoot() registers providers once app-wide, forChild() imports features without re-registering services
forRoot() registers singleton services once at the app root, while forChild() lets feature modules use the module's directives without duplicating providers.
Question 7: In Express.js, what is the correct way to access URL query parameters from a request like `/search?term=node&page=2`?
- req.params.term
- req.query.term (Correct answer)
- req.body.term
- req.url.term
Correct answer: req.query.term
req.query contains key-value pairs from the URL query string, so req.query.term would return 'node' for that URL.
Which Angular RxJS operator should you use to cancel a previous HTTP request when a new search term is typed quickly?