0% found this document useful (0 votes)
3 views5 pages

50 NodeJS Interview Questions

Uploaded by

Swayam Jilla
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views5 pages

50 NodeJS Interview Questions

Uploaded by

Swayam Jilla
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Here are 50 Node.

js interview questions categorized from beginner to advanced levels, with concise


answers.

Beginner Level

1. What is [Link]?

o [Link] is a JavaScript runtime built on Chrome's V8 engine that allows JavaScript to


run on the server side.

2. What is npm?

o npm (Node Package Manager) is the default package manager for [Link] that
manages dependencies and packages.

3. What is the difference between [Link] and JavaScript?

o JavaScript runs on the browser, while [Link] allows JavaScript to run on the server.

4. What is [Link]?

o [Link] is a file that holds metadata about a [Link] project, including its
dependencies.

5. What are modules in [Link]?

o Modules are reusable blocks of code that can be exported and imported in [Link]
using require() or import().

6. What is require() in [Link]?

o require() is a function used to import modules in [Link].

7. What is the purpose of [Link]?

o [Link] is used to export objects, functions, or variables from a [Link]


module.

8. What is the event-driven architecture in [Link]?

o [Link] follows an event-driven architecture where operations are performed


asynchronously, and events trigger corresponding actions.

9. What is the use of the fs module?

o The fs (file system) module allows [Link] to interact with the file system, such as
reading and writing files.

10. What is a callback function in [Link]?

o A callback function is a function passed as an argument to another function, which is


executed after the completion of an asynchronous operation.

11. What is the difference between synchronous and asynchronous functions?

o Synchronous functions block the code execution, while asynchronous functions allow
the execution of other tasks while waiting for an operation to complete.
12. What is non-blocking I/O?

o Non-blocking I/O allows [Link] to process multiple requests without waiting for the
completion of one task before starting the next.

13. What is process in [Link]?

o process is a global object that provides information and control over the current
[Link] process.

14. What are streams in [Link]?

o Streams are objects used to read or write data continuously, like handling large files.

15. What is the difference between readFile and createReadStream in [Link]?

o readFile reads the entire file into memory, while createReadStream reads the file in
chunks, making it more memory-efficient.

16. What is middleware in [Link]?

o Middleware is a function that processes requests in the [Link] framework before


passing them to the next function.

17. How does [Link] handle child processes?

o [Link] has a child_process module to spawn child processes and execute shell
commands.

18. What is path in [Link]?

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

19. What is the use of the http module in [Link]?

o The http module enables [Link] to create an HTTP server and handle HTTP requests
and responses.

20. What are buffers in [Link]?

o Buffers are temporary memory spaces that store raw binary data, typically used in
file handling.

Intermediate Level

21. What is an event loop in [Link]?

o The event loop is the mechanism that allows [Link] to perform non-blocking I/O
operations by offloading operations to the system kernel whenever possible.

22. What is a promise in [Link]?

o A promise is an object that represents the eventual completion (or failure) of an


asynchronous operation and its resulting value.

23. What is the difference between Promise and async/await?


o async/await is syntactic sugar over promises, making asynchronous code look
synchronous.

24. What is the purpose of next() in [Link]?

o next() passes control to the next middleware function in the stack.

25. What is clustering in [Link]?

o Clustering enables the creation of child processes (workers) to take advantage of


multi-core systems.

26. How can you handle exceptions in [Link]?

o Exceptions can be handled using try...catch blocks or by listening to the error event
in asynchronous operations.

27. What is a RESTful API in [Link]?

o A RESTful API follows REST principles, allowing client-server communication via


standard HTTP methods (GET, POST, PUT, DELETE).

28. What is CORS in [Link]?

o CORS (Cross-Origin Resource Sharing) is a mechanism that allows controlled access


to resources from different domains.

29. How do you handle file uploads in [Link]?

o File uploads are typically handled using middleware like multer in [Link].

30. What are JWTs and how are they used in [Link]?

o JSON Web Tokens (JWTs) are a compact way to securely transmit information
between parties, often used for authentication.

31. How does [Link] handle memory management?

o [Link] uses V8’s garbage collector for memory management, which reclaims
memory that is no longer in use.

32. What is the difference between PUT and POST?

o PUT is idempotent and updates existing resources, while POST is used to create new
resources.

33. What are microservices in [Link]?

o Microservices are an architectural style that structures an application as a collection


of loosely coupled services, each responsible for a specific functionality.

34. What is the difference between [Link]() and setImmediate()?

o [Link]() schedules the callback to be executed in the current phase, while


setImmediate() schedules it for the next iteration of the event loop.

35. How can you implement caching in [Link]?


o Caching can be implemented using in-memory solutions like Redis or through HTTP
caching headers.

36. What is socket programming in [Link]?

o Socket programming involves real-time communication between a client and server


using WebSockets.

37. What is the use of environment variables in [Link]?

o Environment variables store configuration data, which can be accessed using


[Link] in [Link].

38. How do you secure a [Link] application?

o Security in [Link] can be ensured through practices like validating input, using
HTTPS, and employing libraries like helmet for setting security-related HTTP headers.

39. What is middleware chaining in [Link]?

o Middleware chaining allows multiple middleware functions to handle a request


sequentially.

40. What is nodemon?

o nodemon is a tool that automatically restarts a [Link] application when file changes
are detected.

Advanced Level

41. What is the purpose of cluster module in [Link]?

o The cluster module allows [Link] to create child processes that share the same
server port, improving performance on multi-core systems.

42. How does [Link] handle asynchronous operations internally?

o [Link] delegates async operations to the system's kernel and uses the event loop to
process callbacks once the operations are completed.

43. What are worker threads in [Link]?

o Worker threads enable running JavaScript in parallel in multiple threads, useful for
CPU-intensive tasks.

44. How do you optimize a [Link] application for production?

o Optimization strategies include using clustering, load balancing, caching, and


monitoring tools.

45. What is streams2 in [Link]?

o streams2 is an improved version of the original streams implementation in [Link],


fixing some issues and introducing backpressure.

46. What is backpressure in [Link] streams?


o Backpressure is a situation where the source of data is producing data faster than it
can be processed, and streams handle this by managing flow control.

47. What is the difference between horizontal and vertical scaling in [Link]?

o Horizontal scaling involves adding more servers (nodes), while vertical scaling means
adding more resources (CPU, RAM) to the same server.

48. What are native bindings in [Link]?

o Native bindings allow [Link] to call C/C++ code from JavaScript for performance-
critical operations.

49. What is V8 and how does it impact [Link] performance?

o V8 is the JavaScript engine used by [Link], which compiles JavaScript directly to


machine code, improving performance.

50. How can you monitor and profile a [Link] application?

o Monitoring and profiling can be done using tools like pm2, New Relic, or [Link]’s
built-in inspector tool for performance analysis.

You might also like