Building a simple REST API with NodeJS and Express Quiz

Explore how to set up a basic REST API using NodeJS and Express, manage dependencies, and serve both static files and data. This quiz covers foundational backend development concepts in a NodeJS environment.

  1. NodeJS Installation

    Which approach is recommended to ensure you install a stable and reliable version of NodeJS for backend development?

    1. Download the most stable release from the official NodeJS website
    2. Use only pre-installed versions found in your operating system
    3. Directly clone the NodeJS source code repository
    4. Install any beta version available

    Explanation: Downloading the most stable release ensures you get a reliable version suitable for production use, minimizing the risk of bugs and future incompatibility. Beta versions may contain unstable features. Cloning the source code is unnecessary for most users and can be complex. Relying on pre-installed versions may provide outdated software.

  2. Role of package.json

    What is the primary purpose of the package.json file in a NodeJS application?

    1. To handle user authentication
    2. To compile JavaScript files automatically
    3. To describe the app's metadata and manage its dependencies
    4. To provide a backup of static files

    Explanation: The package.json file holds essential information about the app and lists all dependencies, making it easy to manage and share projects. JavaScript compilation and user authentication are not handled by package.json. Backing up static files is unrelated to its function.

  3. Initializing NodeJS Apps

    Which command interactively creates a package.json file while initializing a new NodeJS project?

    1. node start
    2. npm script create
    3. npm init
    4. npm install express

    Explanation: Running 'npm init' interactively generates the package.json file, prompting for input. 'node start' is not a valid initialization command. 'npm install express' installs Express but does not create package.json by itself. 'npm script create' is not a recognized npm command.

  4. use of express-generator

    What does the -g flag do when installing the express-generator tool with npm?

    1. It gives express-generator higher priority over local modules
    2. It generates sample files in the current directory
    3. It installs the tool globally for all projects on the system
    4. It updates all global packages

    Explanation: The -g flag installs a module globally, making it accessible from anywhere on your system. It does not generate files, update all global packages, or change module priority.

  5. Serving Static Files vs Data

    What is the key difference between serving static files and serving data in a NodeJS backend?

    1. Static files are always images, while data is always JSON
    2. Static files require user authentication, while data does not
    3. Static files are sent as-is, while data responses are typically generated dynamically
    4. Data can only be served externally, not internally

    Explanation: Static files like HTML, CSS, and JavaScript are delivered unchanged, while data responses can be dynamically generated or processed by the server. Authentication is not inherent to either, and both static files and data responses can vary in format.