Node.
js Interview Questions and Answers
1. What is Node.js?
Answer: Node.js is an open-source, cross-platform JavaScript runtime environment that executes
JavaScript code outside a web browser. It uses the V8 engine and is designed for building scalable
network applications.
2. What are the key features of Node.js?
Answer: - Asynchronous and Event-driven
- Very fast (V8 engine)
- Single-threaded but highly scalable
- No buffering
- Cross-platform
3. How is Node.js different from JavaScript in the browser?
Answer: Node.js runs JavaScript on the server-side, while browser JavaScript runs on the
client-side. Node provides APIs for file system, HTTP, etc., which are not available in the browser.
4. What is the use of npm?
Answer: npm (Node Package Manager) is used to manage dependencies (libraries and packages)
in Node.js projects.
5. What is the difference between npm and npx?
Answer: npm installs packages, while npx executes packages without installing them globally.
6. What is the Event Loop in Node.js?
Answer: The event loop is a mechanism that handles asynchronous callbacks. It allows Node.js to
perform non-blocking I/O operations despite being single-threaded.
7. What are modules in Node.js?
Answer: Modules are reusable blocks of code. Node.js has built-in modules (fs, http, etc.),
third-party modules (via npm), and custom modules.
8. How do you export and import a module in Node.js?
Answer: Use `module.exports = value` to export and `require('module')` to import.
9. What is a callback function?
Answer: A callback is a function passed into another function to be executed later, often after an
async task.
10. What is package.json?
Answer: It is a metadata file that includes details like project name, version, scripts, and
dependencies.