MEAN Stack Development 4 — Questions and Answers
Question 1: What is the purpose of Angular's `HttpClientModule`?
- To manage component lifecycle hooks
- To enable making HTTP requests to backend APIs (Correct answer)
- To set up Angular routing
- To handle form validation
Correct answer: To enable making HTTP requests to backend APIs
HttpClientModule provides the HttpClient service, which Angular applications use to communicate with REST APIs over HTTP.
Question 2: Which Mongoose method finds a single document by its `_id` field?
- Model.findOne()
- Model.findById() (Correct answer)
- Model.getById()
- Model.fetch()
Correct answer: Model.findById()
Model.findById() is a Mongoose shorthand for Model.findOne({ _id: id }) and returns the document with the matching ID.
Question 3: In Node.js, what is the purpose of the `package.json` `scripts` field?
- Lists all installed npm packages
- Defines shortcuts for running commands via npm run (Correct answer)
- Specifies the Node.js version requirement
- Maps module aliases for imports
Correct answer: Defines shortcuts for running commands via npm run
The scripts field defines named command shortcuts runnable with `npm run <scriptName>`, commonly used for start, test, and build tasks.
Question 4: What Angular concept allows components to communicate from a child to a parent component?
- @Input()
- Two-way binding with ngModel
- @Output() with EventEmitter (Correct answer)
- Service injection
Correct answer: @Output() with EventEmitter
@Output() combined with EventEmitter lets a child component emit events that the parent component can listen to and respond to.
Question 5: In MongoDB, what does the `$lookup` aggregation stage accomplish?
- Searches text fields using full-text search
- Performs a left outer join with another collection (Correct answer)
- Creates a new index on a field
- Filters documents based on a condition
Correct answer: Performs a left outer join with another collection
$lookup performs a left outer join to another collection in the same database, enriching documents with related data.
Question 6: What does CORS stand for, and why is it relevant in MEAN stack development?
- Common Object Routing System — manages Express routes
- Cross-Origin Resource Sharing — controls which domains can access the API (Correct answer)
- Component Object Reference Schema — defines Angular data models
- Cache Origin Response Strategy — optimizes MongoDB queries
Correct answer: Cross-Origin Resource Sharing — controls which domains can access the API
CORS (Cross-Origin Resource Sharing) is a browser security mechanism that must be configured in Express to allow the Angular frontend on a different port to call the API.
Question 7: Which of the following best describes Node.js's single-threaded event loop model?
- Node.js creates a new thread for every incoming HTTP request
- Node.js uses one thread but offloads I/O operations asynchronously via the event loop (Correct answer)
- Node.js is multi-threaded and uses worker pools for all tasks
- Node.js blocks execution until each I/O operation completes
Correct answer: Node.js uses one thread but offloads I/O operations asynchronously via the event loop
Node.js runs JavaScript on a single thread but handles I/O non-blocking via the event loop and libuv thread pool, enabling high concurrency.
What is the purpose of Angular's `HttpClientModule`?