Node.js Backend web service/API. Part 1 Quiz

Explore fundamental principles for setting up a scalable and maintainable Node.js backend API, including dependencies, folder structure, and initial configurations.

  1. Project Setup Essentials

    Which three main dependencies are considered essential when setting up a Node.js backend API focused on scalability and code quality?

    1. MongoDB, Express, Angular
    2. Node.js, MongoDB, Babel
    3. Babel, PostgreSQL, Vue.js
    4. Node.js, React, MySQL

    Explanation: Node.js provides the runtime for JavaScript on the server, MongoDB serves as the NoSQL database, and Babel ensures compatibility and modern code syntax. The other options incorrectly list frontend frameworks or unrelated databases, which are not primary backend dependencies for this setup.

  2. Project Folder Structure

    What is typically stored in the 'src' folder when organizing a Node.js API project?

    1. Source code files
    2. Database files
    3. Compiled build files
    4. User-uploaded images

    Explanation: The 'src' folder conventionally holds the project's source code, making the codebase organized and maintainable. Database files and user images are not stored here, and compiled builds are usually found in a 'dist' or 'build' directory.

  3. Configuration Management

    What is the main purpose of having a 'config' folder in a Node.js backend API project?

    1. Handle routing logic
    2. Manage user sessions
    3. Store application environment variables
    4. Keep frontend static assets

    Explanation: A 'config' folder is used to store configuration files and environment variables necessary for the application. Frontend assets and user session logic do not belong there, and routing is typically managed in specific route or controller files.

  4. Initialization Order

    In a typical Node.js API entry file, which order captures the usual initialization steps?

    1. Express, Server creation, Routes, Database
    2. Server creation, Express, Database, Routes
    3. Routes, Database, Server creation, Express
    4. Database, Express, Routes, Server creation

    Explanation: The preferred sequence is to initialize the database first for data connectivity, then set up Express, integrate routes, and finally start the server. Other sequences either misplace the order or initialize critical components too late.

  5. API Route Loading

    What is the purpose of using a middleware such as 'ApiAuth' before loading API routes in a backend project?

    1. To parse JSON data
    2. To compress API responses
    3. To render frontend views
    4. To ensure client authorization

    Explanation: Middleware like 'ApiAuth' is designed to verify that clients are authorized before accessing API endpoints. Response compression and JSON parsing are handled by other middlewares, and rendering frontend views is not typical in pure API projects.