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
- Runtime and event loop
- Modules and npm
- Asynchronous code and callbacks
- Basic servers and the file system
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?
- A JavaScript runtime environment
- A database
- A CSS framework
- 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?
- V8
- SpiderMonkey
- JavaScriptCore
- Chakra
Answer: V8
Node.js uses Google's V8 JavaScript engine.
3. Which command checks the installed Node.js version?
- node -v
- node version
- npm -node
- node check
Answer: node -v
The node -v command displays the installed Node.js version.
4. What does npm stand for?
- Node Package Manager
- New Programming Module
- Node Program Manager
- 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?
- npm init
- npm create
- node init
- 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?
- http
- server
- web
- network
Answer: http
Node.js provides the built-in http module for creating HTTP servers.
7. Which command installs a package using npm?
- npm install package-name
- node install package-name
- npm add-file package-name
- 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?
- package.json
- index.html
- style.css
- server.txt
Answer: package.json
package.json stores project information, scripts, and dependencies.
9. Is Node.js single-threaded?
- Yes, its JavaScript execution is primarily single-threaded
- No, it always uses multiple JavaScript threads
- Only on Windows
- 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?
- Event-driven and non-blocking
- Only synchronous
- Database-driven only
- 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?
- process
- node
- system
- 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?
- fs
- file
- files
- 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?
- path
- directory
- url
- location
Answer: path
The path module provides utilities for working with file and directory paths.
14. What is Express.js?
- A web framework for Node.js
- A database
- A JavaScript engine
- 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?
- listen()
- start()
- run()
- 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?
- A function passed to another function to be executed later
- A database query
- A Node.js package
- 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?
- I/O operations
- Only CSS styling
- HTML formatting
- 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?
- .gitignore
- .nodeignore
- ignore.txt
- 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?
- node filename.js
- npm run filename.js
- run node filename.js
- 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?
- Non-blocking I/O
- Synchronous execution only
- HTML rendering
- CSS processing
Answer: Non-blocking I/O
Node.js's non-blocking I/O model allows it to handle many concurrent connections efficiently.