Node.js Quiz

Node.js lets you run JavaScript on the server. This quiz looks at the runtime, modules, the event loop, asynchronous programming, npm and building simple servers and APIs.

What this quiz covers

Study tip: Write a tiny HTTP server and log the order in which callbacks run; it makes the event loop much easier to understand.

Questions, answers and explanations

1. What is Node.js?

  1. A JavaScript runtime environment
  2. A database
  3. A CSS framework
  4. A web browser

Answer: A JavaScript runtime environment

Node.js allows JavaScript to run outside the browser.

2. Which JavaScript engine does Node.js use?

  1. V8
  2. SpiderMonkey
  3. JavaScriptCore
  4. Chakra

Answer: V8

Node.js uses Google's V8 JavaScript engine.

3. Which command checks the installed Node.js version?

  1. node -v
  2. node version
  3. npm -node
  4. node check

Answer: node -v

The node -v command displays the installed Node.js version.

4. What does npm stand for?

  1. Node Package Manager
  2. New Programming Module
  3. Node Program Manager
  4. Network Package Manager

Answer: Node Package Manager

npm is the package manager commonly used with Node.js.

5. Which command creates a package.json file?

  1. npm init
  2. npm create
  3. node init
  4. npm package

Answer: npm init

npm init creates a package.json file for a Node.js project.

6. Which module is used to create a web server in Node.js?

  1. http
  2. server
  3. web
  4. network

Answer: http

Node.js provides the built-in http module for creating HTTP servers.

7. Which command installs a package using npm?

  1. npm install package-name
  2. node install package-name
  3. npm add-file package-name
  4. node package package-name

Answer: npm install package-name

npm install downloads and installs packages into a Node.js project.

8. Which file commonly contains Node.js project dependencies?

  1. package.json
  2. index.html
  3. style.css
  4. server.txt

Answer: package.json

package.json stores project information, scripts, and dependencies.

9. Is Node.js single-threaded?

  1. Yes, its JavaScript execution is primarily single-threaded
  2. No, it always uses multiple JavaScript threads
  3. Only on Windows
  4. Only when using npm

Answer: Yes, its JavaScript execution is primarily single-threaded

Node.js uses a single JavaScript thread with an event-driven architecture and can use background threads for certain operations.

10. What architecture is commonly associated with Node.js?

  1. Event-driven and non-blocking
  2. Only synchronous
  3. Database-driven only
  4. HTML-driven

Answer: Event-driven and non-blocking

Node.js is designed around an event-driven, non-blocking I/O model.

11. Which object provides information about the current Node.js process?

  1. process
  2. node
  3. system
  4. runtime

Answer: process

The built-in process object provides information and control over the current Node.js process.

12. Which module is used to work with files in Node.js?

  1. fs
  2. file
  3. files
  4. storage

Answer: fs

The built-in fs module provides APIs for working with files and directories.

13. Which module is used to work with file and directory paths?

  1. path
  2. directory
  3. url
  4. location

Answer: path

The path module provides utilities for working with file and directory paths.

14. What is Express.js?

  1. A web framework for Node.js
  2. A database
  3. A JavaScript engine
  4. An operating system

Answer: A web framework for Node.js

Express.js is a popular framework for building web applications and APIs with Node.js.

15. Which method starts a Node.js HTTP server?

  1. listen()
  2. start()
  3. run()
  4. open()

Answer: listen()

The server.listen() method starts an HTTP server and listens for incoming connections.

16. What is a callback function in Node.js?

  1. A function passed to another function to be executed later
  2. A database query
  3. A Node.js package
  4. A type of server

Answer: A function passed to another function to be executed later

Callbacks are commonly used to handle asynchronous operations in Node.js.

17. What does asynchronous programming help Node.js handle efficiently?

  1. I/O operations
  2. Only CSS styling
  3. HTML formatting
  4. Image editing

Answer: I/O operations

Node.js uses asynchronous I/O to handle tasks such as file access and network requests efficiently.

18. Which file is commonly used to ignore files in a Node.js project when using Git?

  1. .gitignore
  2. .nodeignore
  3. ignore.txt
  4. package.ignore

Answer: .gitignore

The .gitignore file tells Git which files and directories should not be tracked.

19. Which command runs a Node.js JavaScript file?

  1. node filename.js
  2. npm run filename.js
  3. run node filename.js
  4. javascript filename.js

Answer: node filename.js

The node command executes a JavaScript file using the Node.js runtime.

20. Which feature makes Node.js suitable for applications with many concurrent connections?

  1. Non-blocking I/O
  2. Synchronous execution only
  3. HTML rendering
  4. CSS processing

Answer: Non-blocking I/O

Node.js's non-blocking I/O model allows it to handle many concurrent connections efficiently.

Take the timed quiz