0% found this document useful (0 votes)
28 views15 pages

Top 50 Node.js Interview Questions

The document is a compilation of the top 50 interview questions related to Node.js, covering essential concepts such as Node.js itself, NPM, event loops, middleware, and APIs. Each question is followed by a concise answer that explains the topic in a straightforward manner. This resource serves as a study guide for individuals preparing for Node.js interviews.

Uploaded by

Swamy
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)
28 views15 pages

Top 50 Node.js Interview Questions

The document is a compilation of the top 50 interview questions related to Node.js, covering essential concepts such as Node.js itself, NPM, event loops, middleware, and APIs. Each question is followed by a concise answer that explains the topic in a straightforward manner. This resource serves as a study guide for individuals preparing for Node.js interviews.

Uploaded by

Swamy
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

Lokesh Mali

Website Developer

TOP 50
TOP 50
NODE
INTERVIEW QUESTIONS
Lokesh Mali

Q 1.
Q 1. W
What
h a t iiss N
[Link]?
[Link]?
ANS: [Link] is a JavaScript runtime built on the V8
engine. It allows JavaScript to run on the
server side. It is fast and event-driven.

Q 2.
Q 2. W
What
h a t iiss N
NPM?
PM?
ANS: NPM is the default package manager for
[Link]. It helps install libraries and manage
dependencies. It also hosts millions of open-
source packages.

Q 3.
Q 3. W
What
h a t iiss E
Event Loop
vent L o o p iin [Link]?
n N [Link]?
ANS: The event loop handles asynchronous tasks in
[Link]. It allows non-blocking operations. This
makes [Link] highly scalable.

Q 4.
Q 4. W
What
h a t iiss n
non-blocking
o n - b l o c k i n g II/O?
/O?
ANS: Non-blocking I/O means tasks run without
waiting for others to complete. [Link] uses
this for fast performance. It helps handle many
requests at once.

1
Lokesh Mali

Q 5.
Q 5. W
What are
hat a [Link]
re N modules?
[Link] m odules?
ANS: Modules are reusable blocks of code in [Link].
They help organize and structure applications.
They can be built-in, custom, or third-party.

Q 6.
Q 6. W
What
h a t iiss C
CommonJS?
ommonJS?
ANS: CommonJS is the module system used by [Link]
(require/export). It loads modules synchronously.
It’s used in server-based applications.

Q 7.
Q 7. DDifference between
ifference b e t w e e n rrequire()
equire()
and
a n d iimport?
mport?
ANS: require() is CommonJS and works synchronously.
import is ES6 and works asynchronously. Modern
[Link] supports both.

Q 8.
Q 8. W
What
h a t iiss E
[Link]?
[Link]?
ANS: [Link] is a web framework for [Link]. It
simplifies routing and middleware handling. It
helps build APIs quickly.

2
Lokesh Mali

Q 9.
Q 9. W
What
h a t iiss m
middleware
i d d l e w a r e iin Express?
n E xpress?
ANS: Middleware is a function that handles requests
before the response. It can modify request/response
objects. It’s used for auth, logging, etc.

Q 10.
Q 10. W
What
h a t iiss p
[Link]?
[Link]?
ANS: [Link] stores project metadata,
dependencies, and scripts. It is required for every
[Link] project. It helps manage and run the
application.

Q 11.
Q 11. W
What
h a t iiss c
callback
a l l b a c k iin [Link]?
n N [Link]?
ANS: A callback is a function executed after another
function completes. [Link] heavily uses
callbacks for async operations. It can sometimes
cause callback hell.

Q 12.
Q 12. W
What
h a t iiss c
callback hell?
allback h ell?
ANS: Callback hell occurs when multiple callbacks
are nested. It makes code difficult to read and
manage. Promises and async/await solve this.

3
Lokesh Mali

Q 13.
Q 13. W
What
h a t iiss a
a PPromise?
romise?
ANS: A promise represents an async operation result. It
has states like pending, fulfilled, and rejected. It
helps avoid callback hell.

Q 14.
Q 14. W
What
h a t iiss a
async/await?
sync/await?
ANS: Async/await makes asynchronous code look
synchronous. It simplifies promise handling. It
improves readability.

Q 15.
Q 15. W
What
h a t iiss S
Streams
t r e a m s iin [Link]?
n N [Link]?
ANS: Streams process data in chunks instead of loading
it fully. It improves performance for large data.
Streams are readable, writable, or both.

Q 16.
Q 16. W
What
h a t iiss B
Buffer
u f f e r iin [Link]?
n N [Link]?
ANS: Buffer is used to store binary data in [Link]. It
helps handle raw data from streams or files. It is
faster than using strings for binary data.

4
Lokesh Mali

Q 17.
Q 17. W
What
h a t iiss tthe difference
he d between
ifference b etween
[Link]() and
[Link]() a nd
setImmediate()?
setImmediate()?
ANS: [Link]() executes before the next event
loop iteration. setImmediate() executes on the next
iteration. Both are used for async operations.

Q 18.
Q 18. W
What
h a t iiss tthe difference
he d between
ifference b etween
[Link]
N and
[Link] a JavaScript?
nd J avaScript?
ANS: JavaScript runs in the browser. [Link] runs on
the server. [Link] adds features like file system
and network access.
Q 19.
Q 19. W
What are
hat a r e tthe
h e ttypes off AAPI
ypes o P I iin
n
[Link]?
N [Link]?
ANS: [Link] APIs are of three types: File System API,
HTTP API, and Stream API. They allow interaction
with OS, network, and files.
Q 20.
Q What
20. W h a t iiss tthe difference
he d between
ifference b etween
sspawn() and
pawn() a n d ffork()?
ork()?
ANS: spawn() launches a new process with a
command. fork() spawns a new [Link] process.
fork() allows communication via IPC. 5
Lokesh Mali

Q 21.
Q 21. W
What
h a t iiss c
clustering
l u s t e r i n g iin [Link]?
n N [Link]?
ANS: Clustering allows [Link] to create multiple worker
processes. Each worker runs on a separate CPU core.
It improves performance on multi-core machines.

Q 22.
Q 22. W
What
h a t iiss R
REPL
E P L iin [Link]?
n N [Link]?
ANS: REPL stands for Read-Eval-Print Loop. It allows
executing [Link] commands interactively.
Useful for testing code snippets quickly.

Q 23.
Q 23. W
What
h a t iiss tthe difference
he d between
ifference b etween
rreadFile() and
eadFile() a createReadStream()?
nd c reateReadStream()?
ANS: readFile() reads the entire file into memory.
createReadStream() reads data in chunks.
Streams are better for large files.

Q 24.
Q 24. W
What
h a t iiss tthe difference
he d between
ifference b etween
[Link]
p and
[Link] a config
nd c o n f i g ffiles?
iles?
ANS: [Link] stores environment variables.
Config files store application settings. Env
variables are preferred for sensitive info.

6
Lokesh Mali

Q 25.
Q 25. W
What
h a t iiss tthe difference
he d between
ifference b etween
PUT
P and
UT a PATCH?
nd P ATCH?
ANS: PUT updates the entire resource. PATCH updates
only specific fields. Both are used in REST APIs.

Q 26.
Q 26. HHow doo yyou
ow d handle
ou h errors
andle e r r o r s iin
n
[Link]?
N [Link]?
ANS: Errors can be handled using callbacks, try/catch,
or promises. Express apps often use error-
handling middleware. Proper handling prevents
crashes.
Q 27.
Q 27. W
What
h a t iiss C
CORS?
ORS?
ANS: CORS (Cross-Origin Resource Sharing) allows
resources to be shared between different
origins. Browsers enforce CORS for security.
Express has middleware to handle it.

Q 28.
Q 28. W
What
h a t iiss J
JWT
W T iin [Link]?
n N [Link]?
ANS: JWT (JSON Web Token) is used for
authentication. It securely transmits info
between client and server. Often used with APIs.

7
Lokesh Mali

Q 29.
Q 29. W
What
h a t iiss tthe difference
he d between
ifference b etween
synchronous and
synchronous a asynchronous
nd a synchronous
code?
code?
ANS: Synchronous code runs line by line, blocking the
next operation. Asynchronous code runs without
waiting. [Link] uses async code for efficiency.

Q 30.
Q 30. HHow doo yyou
ow d debug
ou d [Link]
ebug N [Link]
applications?
a pplications?

ANS: [Link] apps can be debugged using [Link](),


the built-in debugger, or Chrome DevTools. VS
Code also has debugging tools. It helps identify
issues quickly.

Q 31.
Q 31. W h a t is
What i s tthe difference
he d between
ifference b etween
HTTP
HTTP a andnd HHTTPS?
TTPS?

ANS: HTTP is unsecured while HTTPS is secured using


SSL/TLS. HTTPS encrypts data between client
and server. Most APIs and websites use HTTPS
for security.
8
Lokesh Mali

Q 32.
Q 32. W
What
h a t iiss a
a RREST API?
EST A PI?
ANS: REST API allows communication between client and
server using HTTP methods. It is stateless and uses
JSON/XML. Widely used in web applications.

Q 33.
Q 33. W
What
h a t iiss tthe difference
he d between
ifference b etween
[Link]('exit') and
[Link]('exit') a nd
[Link]('beforeExit')?
[Link]('beforeExit')?
ANS: [Link]('exit') triggers when [Link] exits, no
async allowed. [Link]('beforeExit') triggers
before exit, async tasks can run. Useful for
cleanup.

Q 34.
Q 34. W
What
h a t iiss tthe difference
he d between
ifference b etween
[Link]() and
[Link]() a n d [Link]()?
[Link]()?
ANS: [Link]() sends any response type. [Link]()
specifically sends JSON and sets content-type
automatically. [Link]() is preferred for APIs.

Q 35.
Q 35. HHow doo yyou
ow d handle
ou h a n d l e ffile uploads
ile u ploads
iin [Link]?
n N [Link]?
ANS: File uploads can be handled using middleware like
Multer. It parses multipart/form-data requests.
Files can then be saved on disk or cloud storage.
9
Lokesh Mali

Q 36.
Q 36. W
What
h a t iiss tthe difference
he d between
ifference b etween
cluster
c and
luster a worker
nd w o r k e r tthreads?
hreads?
ANS: Cluster creates multiple [Link] processes to
handle load. Worker threads allow multi-threading
in a single process. Both improve performance
differently.
Q 37.
Q 37. W
What
h a t iiss tthe difference
he d between
ifference b etween
ssetTimeout() and
etTimeout() a n d ssetInterval()?
etInterval()?
ANS: setTimeout() runs a function once after a delay.
setInterval() runs a function repeatedly at
intervals. Both are asynchronous timers in
[Link].
Q 38.
Q 38. W
What
h a t iiss tthe difference
he d between
ifference b etween
cluster
c and
luster a PM2?
nd P M2?
ANS: Cluster is a [Link] module for multi-core process
handling. PM2 is a process manager for production,
supporting clustering and monitoring. PM2 simplifies
deployment.
Q 39.
Q 39. HHow does
ow d [Link]
oes N handle
[Link] h child
andle c hild
processes?
p rocesses?
ANS: [Link] can create child processes using spawn(),
fork(), or exec(). Child processes allow parallel
execution of tasks. Useful for CPU-intensive
operations.
10
Lokesh Mali

Q 40.
Q 40. W
What
h a t iiss tthe difference
he d between
ifference b etween
synchronous
synchronous a and asynchronous
nd a synchronous
file operations?
file o perations?
ANS: Synchronous file operations block execution until
completed. Asynchronous operations don’t block,
using callbacks or promises. Async is preferred for
scalability.
Q 41.
Q 41. W
What
h a t iiss a
a ttemplate engine
emplate e n g i n e iin
n
[Link]?
N [Link]?
ANS: Template engines like EJS, Pug generate HTML
dynamically. They help render data on server-side.
Useful for building dynamic web pages.
Q 42.
Q 42. W
What
h a t iiss N
[Link] REPL?
[Link] R EPL?
ANS: REPL (Read-Eval-Print Loop) lets you run [Link]
commands interactively. Useful for testing code
snippets. Available via terminal by typing node.

Q 43.
Q 43. W
What
h a t iiss tthe difference
he d between
ifference b etween
local and
local a global
nd g modules
lobal m o d u l e s iin
n
[Link]?
[Link]?
ANS: Local modules are installed per project using npm.
Global modules are installed system-wide. Global
modules can be used in any project.

11
Lokesh Mali

Q 44.
Q 44. W
What
h a t iiss tthe difference
he d between
ifference b etween
[Link]() and
[Link]() a nd
child_process.fork()?
child_process.fork()?
ANS: [Link]() creates multiple workers for load
balancing. child_process.fork() creates a single
[Link] child process. Both allow inter-process
communication.
Q 45.
Q 45. W
What are
hat a [Link]
re N o d e . j s ttimers?
imers?
ANS: Timers like setTimeout(), setInterval(), and
setImmediate() schedule functions to run later.
They are part of the [Link] event loop. Useful for
async scheduling.
Q 46.
Q 46. W
What
h a t iiss tthe difference
he d between
ifference b etween
cluster module
cluster m and
odule a nd
worker_threads
worker_threads mmodule?
odule?
ANS: Cluster creates multiple [Link] processes for
parallelism. worker_threads allows multi-threading
within a single process. worker_threads share
memory while clusters do not.
Q 47.
Q 47. W
What
h a t iiss p
[Link]
r o c e s s . a r g v iin [Link]?
n N [Link]?
ANS: [Link] stores command-line arguments
passed to a [Link] program. First two elements are
node path and script path. Useful for CLI tools.
12
Lokesh Mali

Q 48.
Q 48. HHow does
ow d [Link]
oes N handle
[Link] h memory
andle m emory
management?
m anagement?

ANS: [Link] uses V8 engine for memory management. It


automatically handles allocation and garbage
collection. Developers should avoid memory leaks.

Q 49.
Q 49. W
What
h a t iiss tthe difference
he d between
ifference b etween
rrequire() and
equire() a n d [Link]()?
[Link]()?
ANS: require() loads a module and executes it.
[Link]() returns the module’s resolved
path without executing it. Useful for checking
module paths.

Q 50.
Q 50. W
What
h a t iiss tthe difference
he d between
ifference b etween
[Link]
N and
[Link] a PHP?
nd P HP?
ANS: [Link] is asynchronous and event-driven. PHP is
synchronous and blocking. [Link] is better for real-
time applications, while PHP is widely used for web
pages.

The End

13
Lokesh Mali
Website Developer

My
CONTENT
HTML CSS BOOTSTRAP

JAVASCRIPT MERN [Link]

WEB DEVELOPMENT INTERVIEW

You might also like