MEAN Stack Development 3 — Questions and Answers
Question 1: What is the role of `app.use()` in an Express.js application?
- Defines a database schema
- Mounts middleware at a specified path (Correct answer)
- Creates a new HTTP server
- Declares Angular routes
Correct answer: Mounts middleware at a specified path
app.use() mounts specified middleware functions at a given path, applying them to all matching incoming requests.
Question 2: Which Node.js module provides an interface for interacting with the file system?
- http
- path
- fs (Correct answer)
- os
Correct answer: fs
The built-in 'fs' (file system) module provides APIs for reading, writing, and manipulating files and directories.
Question 3: In MongoDB, what is the default name of the field used as a document's primary key?
- id
- pk
- _id (Correct answer)
- docId
Correct answer: _id
MongoDB automatically assigns a unique ObjectId to the _id field of every document unless you specify a custom value.
Question 4: What does Angular's `ngFor` structural directive do?
- Conditionally shows or hides an element
- Iterates over a collection and renders a template for each item (Correct answer)
- Applies CSS classes dynamically
- Binds a form control to a model
Correct answer: Iterates over a collection and renders a template for each item
ngFor is a structural directive that renders a template once for each item in an iterable collection.
Question 5: Which of the following is a key advantage of using JWT (JSON Web Tokens) for authentication in a MEAN stack app?
- They are stored server-side for better security
- They are stateless, eliminating server-side session storage (Correct answer)
- They automatically encrypt all API payloads
- They replace the need for HTTPS
Correct answer: They are stateless, eliminating server-side session storage
JWTs are self-contained tokens that carry claims, allowing stateless authentication without maintaining server-side session stores.
Question 6: What does the MongoDB `aggregate()` method allow you to do?
- Insert multiple documents at once
- Process data through a pipeline of transformation stages (Correct answer)
- Create compound indexes
- Merge two collections permanently
Correct answer: Process data through a pipeline of transformation stages
The aggregation pipeline processes documents through sequential stages like $match, $group, and $project to transform and analyze data.
Question 7: In Express.js, which object contains parameters embedded in the URL path such as `/users/:id`?
- req.query
- req.body
- req.params (Correct answer)
- req.headers
Correct answer: req.params
req.params contains named route parameters extracted from the URL path, such as the value of :id.
What is the role of `app.use()` in an Express.js application?