Node.js Runtime Environment
What runtime environment is Node.js based on?
- A. Java Virtual Machine
- B. .NET CLR
- C. V8 JavaScript Engine
- D. Python Interpreter
- E. Ruby on Rails
Node.js Package Manager
Which command is commonly used to initialize a new Node.js project and create a `package.json` file?
- A. npm start
- B. npm install
- C. npm init
- D. node init
- E. npm run
Modules in Node.js
How do you import a built-in module, like the `fs` module, in Node.js?
- A. require('file system')
- B. include fs from 'fs';
- C. import fs from 'fs';
- D. const fs = require('fs');
- E. use fs;
Asynchronous Operations
What is a common method used to handle asynchronous operations in Node.js?
- A. Threads
- B. Blocking operations
- C. Synchronous Loops
- D. Callbacks
- E. While loops
Event Loop
What is the role of the event loop in Node.js?
- A. To manage multiple threads.
- B. To execute JavaScript code synchronously.
- C. To handle incoming network requests.
- D. To monitor the call stack and execute callbacks.
- E. To compile JavaScript into machine code.
Node.js Global Object
What is the equivalent of the `window` object in browsers within the Node.js environment?
- A. globalThis
- B. browser
- C. this
- D. global
- E. window
Creating a Simple Server
Which module is primarily used to create an HTTP server in Node.js?
- A. fs
- B. url
- C. http
- D. path
- E. net
Reading Files Asynchronously
Which function should you use to read a file asynchronously in Node.js using the `fs` module?
- A. fs.readFileSync()
- B. fs.readFileAsync()
- C. fs.readFile()
- D. fs.readSync()
- E. fs.open()
Package.json Dependencies
What is the purpose of the `dependencies` section in a `package.json` file?
- A. To list development dependencies.
- B. To specify the Node.js version required.
- C. To list modules required for production.
- D. To define scripts that can be run.
- E. To list peer dependencies.
Node.js Streams
What are streams in Node.js primarily used for?
- A. Storing data in memory.
- B. Handling asynchronous operations.
- C. Processing large amounts of data efficiently.
- D. Compressing files.
- E. Creating server clusters.
Handling Errors
What is the standard way to handle errors in asynchronous Node.js functions using callbacks?
- A. Try-catch blocks
- B. Throwing exceptions
- C. Returning an error code
- D. Using the first argument of the callback as an error object
- E. Ignoring the error
Express.js Basics
Which HTTP method is commonly used to send data to the server to create or update a resource?
- A. GET
- B. DELETE
- C. PUT
- D. OPTIONS
- E. HEAD
NPM Commands
Which npm command is used to install a package globally?
- A. npm install -g
- B. npm install --global
- C. npm add -g
- D. npm install global
- E. npm add global
Process Object
How can you access command-line arguments passed to a Node.js script?
- A. process.args
- B. process.argv
- C. process.params
- D. arguments
- E. cmdline.arguments
Timers in Node.js
What function is used to execute a piece of code repeatedly after a fixed interval?
- A. setTimeout()
- B. setInterval()
- C. setImmediate()
- D. process.nextTick()
- E. repeat()