Explore foundational concepts for designing a modular, maintainable CRUD API using Node.js, Express, and MongoDB. This quiz highlights best practices for clean architecture, database integration, and efficient backend development.
Which file type is commonly used to store sensitive configuration variables (such as database credentials) in a Node.js project to keep them separate from the codebase?
Explanation: .env is the standard for storing environment variables separately from code, promoting security and flexibility. config.js and settings.json may be used for configuration but are not suited for sensitive secrets. data.csv is a data format, not intended for configuration.
What is the primary purpose of using Mongoose in a Node.js and MongoDB API project?
Explanation: Mongoose is specifically designed to work as an ODM, mapping data between MongoDB and JavaScript objects. Serving static files and request validation are handled by other tools, while job scheduling is managed with libraries like node-cron.
Why is it a best practice to separate controller logic from route definitions in a RESTful API codebase?
Explanation: Separating controllers from routes encourages a clear structure, making the codebase easier to navigate and extend. The other options do not result from this separation; response size, request duplication, and database indexing are unrelated.
Which tool is commonly used to automatically restart a Node.js server upon code changes during development?
Explanation: nodemon monitors file changes and restarts the development server automatically. webpack is a bundler, mongoose is an ODM, and eslint is a linter. None of these others manage server restarts.
What is a key benefit of using a modular folder structure, such as separating models, routes, and controllers, in a backend API project?
Explanation: Organizing code into modules by responsibility simplifies updates and future growth. Faster queries and reduced memory require other optimizations, while documentation requires dedicated tools.