Node.
js Interview Questions
1. What is [Link]?
[Link] is an open-source, cross-platform JavaScript runtime environment that allows
developers to execute JavaScript code outside a web browser.
2. How does [Link] work?
[Link] uses an event-driven, non-blocking I/O model and the V8 JavaScript engine,
making it efficient and lightweight.
3. What is the V8 engine?
V8 is Google’s open-source JavaScript engine that compiles JavaScript directly into
native machine code for improved performance.
4. Why is [Link] single-threaded?
[Link] is single-threaded to efficiently handle concurrent requests using
asynchronous I/O and an event loop.
5. What is the Event Loop in [Link]?
The event loop allows [Link] to handle multiple tasks concurrently by executing
callbacks in the background and managing asynchronous operations.
6. What is the difference between asynchronous and synchronous in [Link]?
o Asynchronous: Non-blocking operations, allowing other tasks to continue
executing.
o Synchronous: Blocking operations that pause execution until the task is
complete.
7. What are callbacks in [Link]?
Functions passed as arguments to other functions, executed after the main function
finishes.
8. What is the difference between [Link]() and setImmediate()?
o [Link](): Executes after the current operation, before the event loop
continues.
o setImmediate(): Executes in the next iteration of the event loop.
9. What are streams in [Link]?
Streams are data-handling objects used for reading or writing data continuously. Types
include readable, writable, duplex, and transform streams.
10. What is a Buffer in [Link]?
Buffers are used to handle binary data in [Link], often when reading from or writing to
streams.
11. Explain the concept of middleware in [Link].
Middleware functions are executed sequentially during request-response cycles,
performing tasks like logging, authentication, and data parsing.
12. What is the [Link] file?
A metadata file in [Link] that holds information about the project, dependencies, and
scripts.
13. What is NPM?
NPM (Node Package Manager) is a tool to install, manage, and share [Link] packages
and dependencies.
14. What is the difference between npm install and npm install --save?
--save ensures the package is added to dependencies in [Link]. (In NPM 5 and
above, --save is the default behavior.)
15. What is the node_modules folder?
A directory where installed dependencies are stored.
16. Explain require and import in [Link].
o require: CommonJS syntax for importing modules.
o import: ES6 module syntax (used with type: module in [Link]).
17. What are the core modules in [Link]?
Examples include fs (File System), http, path, os, events, util, etc.
18. How does [Link] handle concurrency?
[Link] handles concurrency through the event loop and asynchronous I/O operations.
19. What is the global object in [Link]?
An object similar to window in the browser, providing global variables and functions like
__dirname and setTimeout.
20. What are child processes in [Link]?
Child processes allow you to run system commands and spawn new [Link] processes
using the child_process module.
21. What is the cluster module in [Link]?
The cluster module helps create multiple worker processes to take advantage of multi-
core systems.
22. What are the benefits of using [Link]?
o Fast execution
o Non-blocking I/O
o Scalability
o Unified language for front-end and back-end (JavaScript)
23. What is the difference between [Link]() and [Link]()?
o [Link]() reads the entire file into memory.
o [Link]() reads data in chunks, suitable for large files.
24. What is the purpose of the os module in [Link]?
It provides operating system-related utility methods and properties.
25. Explain the util module in [Link].
The util module provides utility functions like promisify and inherits.
[Link] Interview Questions
26. What is [Link]?
[Link] is a minimal, flexible [Link] web application framework for building APIs
and web applications.
27. Why use [Link]?
It simplifies routing, middleware integration, and API creation, speeding up
development.
28. What is routing in [Link]?
Routing defines how the server responds to various HTTP requests (GET, POST, etc.) for
specific URLs.
29. What is the role of middleware in [Link]?
Middleware functions execute before, during, or after request handling, used for
logging, authentication, and parsing.
30. What is [Link]() in Express?
[Link]() mounts middleware functions in the application.
31. What is the difference between [Link]() and [Link]()?
o [Link]() handles GET requests.
o [Link]() handles POST requests.
32. What are the different HTTP methods supported by Express?
GET, POST, PUT, PATCH, DELETE, OPTIONS, and HEAD.
33. How do you handle errors in [Link]?
Using error-handling middleware with four parameters: (err, req, res, next).
34. What is [Link] in Express?
It contains route parameters. Example: /user/:id -> [Link].
35. What is [Link] in Express?
It contains query parameters. Example: /search?name=abc -> [Link].
36. How can you parse incoming JSON data in Express?
Using [Link]() middleware.
37. What is next() in Express middleware?
next() passes control to the next middleware function.
38. What are templating engines in Express?
Tools like EJS, Pug, or Handlebars that render dynamic HTML pages.
39. What is [Link]() in Express?
Sends a response of various types (string, object, etc.).
40. What is [Link]() in Express?
Sends a JSON response.
41. What is the difference between [Link]() and [Link]()?
[Link]() can send any type, while [Link]() specifically sends JSON.
42. What is the purpose of the cookie-parser middleware?
To parse cookies from HTTP requests.
43. How do you secure an Express app?
o Use HTTPS
o Sanitize inputs
o Use Helmet for security headers
44. What is [Link]() in Express?
Redirects a request to a different URL.
45. How do you handle file uploads in Express?
Use libraries like multer for multipart/form-data handling.
46. What is the purpose of [Link]()?
To create modular and mountable route handlers.