Node.js Execution Model
Which of the following correctly describes Node.js's event-driven architecture?
- A. It uses a single-threaded, non-blocking I/O model.
- B. It executes all code in multiple threads automatically.
- C. Node.js always waits for file operations to finish before moving on.
- D. It is based on a blocking, synchronous execution model.
- E. Node.js is primarily designed for CPU-intensive applications.
Built-In Module Import
How do you correctly import the built-in 'fs' module for file operations in Node.js?
- A. const fs = require('fs');
- B. import fs from 'node:os';
- C. let fs = import('filesystem');
- D. require fs from 'fs';
- E. var filesystem = require('file-system');
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?
- A. JSON.parse(fs.readFileSync('data.json', 'utf-8'));
- B. fs.readJSONSync('data.json', 'utf-8');
- C. JSON.decode(fs.readFile('data.json'));
- D. JSON.stringify(fs.readFileSync('data.json'));
- E. fs.readFileSync('data.json').toJson();
Creating HTTP Server
What is the correct way to create a simple HTTP server that responds with 'Hello, world!' in Node.js?
- A. http.createServer((req, res) =u003E { res.end('Hello, world!'); }).listen(3000);
- B. createHttpServer(() =u003E 'Hello, world!').listen(3000);
- C. node.http((req, res) =u003E res.send('Hello, world!')).start(3000);
- D. new http.Server((req, res) =u003E res.output('Hello, world!'));
- E. http.server((req, res) =u003E res.write('Hello, world!')).run(3000);
Handling Uncaught Exceptions
Which event should you listen for to handle uncaught exceptions and prevent Node.js from crashing?
- A. process.on('uncaughtException', ...);
- B. process.on('error', ...);
- C. exception.on('uncaught', ...);
- D. process.listen('exception', ...);
- E. node.on('exception', ...);