Mastering Node.js Basics: A Comprehensive Quiz Quiz

  1. Node.js Runtime Environment

    What runtime environment is Node.js based on?

    1. A. Java Virtual Machine
    2. B. .NET CLR
    3. C. V8 JavaScript Engine
    4. D. Python Interpreter
    5. E. Ruby on Rails
  2. Node.js Package Manager

    Which command is commonly used to initialize a new Node.js project and create a `package.json` file?

    1. A. npm start
    2. B. npm install
    3. C. npm init
    4. D. node init
    5. E. npm run
  3. Modules in Node.js

    How do you import a built-in module, like the `fs` module, in Node.js?

    1. A. require('file system')
    2. B. include fs from 'fs';
    3. C. import fs from 'fs';
    4. D. const fs = require('fs');
    5. E. use fs;
  4. Asynchronous Operations

    What is a common method used to handle asynchronous operations in Node.js?

    1. A. Threads
    2. B. Blocking operations
    3. C. Synchronous Loops
    4. D. Callbacks
    5. E. While loops
  5. Event Loop

    What is the role of the event loop in Node.js?

    1. A. To manage multiple threads.
    2. B. To execute JavaScript code synchronously.
    3. C. To handle incoming network requests.
    4. D. To monitor the call stack and execute callbacks.
    5. E. To compile JavaScript into machine code.
  6. Node.js Global Object

    What is the equivalent of the `window` object in browsers within the Node.js environment?

    1. A. globalThis
    2. B. browser
    3. C. this
    4. D. global
    5. E. window
  7. Creating a Simple Server

    Which module is primarily used to create an HTTP server in Node.js?

    1. A. fs
    2. B. url
    3. C. http
    4. D. path
    5. E. net
  8. Reading Files Asynchronously

    Which function should you use to read a file asynchronously in Node.js using the `fs` module?

    1. A. fs.readFileSync()
    2. B. fs.readFileAsync()
    3. C. fs.readFile()
    4. D. fs.readSync()
    5. E. fs.open()
  9. Package.json Dependencies

    What is the purpose of the `dependencies` section in a `package.json` file?

    1. A. To list development dependencies.
    2. B. To specify the Node.js version required.
    3. C. To list modules required for production.
    4. D. To define scripts that can be run.
    5. E. To list peer dependencies.
  10. Node.js Streams

    What are streams in Node.js primarily used for?

    1. A. Storing data in memory.
    2. B. Handling asynchronous operations.
    3. C. Processing large amounts of data efficiently.
    4. D. Compressing files.
    5. E. Creating server clusters.
  11. Handling Errors

    What is the standard way to handle errors in asynchronous Node.js functions using callbacks?

    1. A. Try-catch blocks
    2. B. Throwing exceptions
    3. C. Returning an error code
    4. D. Using the first argument of the callback as an error object
    5. E. Ignoring the error
  12. Express.js Basics

    Which HTTP method is commonly used to send data to the server to create or update a resource?

    1. A. GET
    2. B. DELETE
    3. C. PUT
    4. D. OPTIONS
    5. E. HEAD
  13. NPM Commands

    Which npm command is used to install a package globally?

    1. A. npm install -g
    2. B. npm install --global
    3. C. npm add -g
    4. D. npm install global
    5. E. npm add global
  14. Process Object

    How can you access command-line arguments passed to a Node.js script?

    1. A. process.args
    2. B. process.argv
    3. C. process.params
    4. D. arguments
    5. E. cmdline.arguments
  15. Timers in Node.js

    What function is used to execute a piece of code repeatedly after a fixed interval?

    1. A. setTimeout()
    2. B. setInterval()
    3. C. setImmediate()
    4. D. process.nextTick()
    5. E. repeat()