Node.js: Test Your Server-side Knowledge Quiz

  1. Node.js Execution Model

    Which of the following correctly describes Node.js's event-driven architecture?

    1. A. It uses a single-threaded, non-blocking I/O model.
    2. B. It executes all code in multiple threads automatically.
    3. C. Node.js always waits for file operations to finish before moving on.
    4. D. It is based on a blocking, synchronous execution model.
    5. E. Node.js is primarily designed for CPU-intensive applications.
  2. Built-In Module Import

    How do you correctly import the built-in 'fs' module for file operations in Node.js?

    1. A. const fs = require('fs');
    2. B. import fs from 'node:os';
    3. C. let fs = import('filesystem');
    4. D. require fs from 'fs';
    5. E. var filesystem = require('file-system');
  3. JSON Handling

    If you want to read and parse a local JSON file called 'data.json' synchronously in Node.js, what code should you use?

    1. A. JSON.parse(fs.readFileSync('data.json', 'utf-8'));
    2. B. fs.readJSONSync('data.json', 'utf-8');
    3. C. JSON.decode(fs.readFile('data.json'));
    4. D. JSON.stringify(fs.readFileSync('data.json'));
    5. E. fs.readFileSync('data.json').toJson();
  4. Creating HTTP Server

    What is the correct way to create a simple HTTP server that responds with 'Hello, world!' in Node.js?

    1. A. http.createServer((req, res) =u003E { res.end('Hello, world!'); }).listen(3000);
    2. B. createHttpServer(() =u003E 'Hello, world!').listen(3000);
    3. C. node.http((req, res) =u003E res.send('Hello, world!')).start(3000);
    4. D. new http.Server((req, res) =u003E res.output('Hello, world!'));
    5. E. http.server((req, res) =u003E res.write('Hello, world!')).run(3000);
  5. Handling Uncaught Exceptions

    Which event should you listen for to handle uncaught exceptions and prevent Node.js from crashing?

    1. A. process.on('uncaughtException', ...);
    2. B. process.on('error', ...);
    3. C. exception.on('uncaught', ...);
    4. D. process.listen('exception', ...);
    5. E. node.on('exception', ...);