Node JS Interview
Node JS Interview
Table of Content
1. What is Node.js?
Node.js JavaScript
Used for building backend APIs, Utilized for creating interactive web
servers, and applications pages and client-side logic
3. Is Node.js single-threaded?
Synchronous
Feature Functions Asynchronous Functions
Executes tasks
Initiates tasks and proceeds
Waiting for sequentially; each task
with other operations while
Completion must complete before
waiting for completion.
the next one starts.
npm (Node Package Manager) is the default package manager for Node.js.
It allows developers to discover, share, and reuse code packages easily. Its
advantages include dependency management, version control, centralized
repository, and seamless integration with Node.js projects.
8. What is middleware?
Middleware is the function that works between the request and the
response cycle. Middleware gets executed after the server receives the
request and before the controller sends the response.
Handling concurrency
REPL in Node.js stands for Read, Evaluate, Print, and Loop. It is a computer
environment similar to the shell which is useful for writing and debugging
code as it executes the code in on go.
We use the require module to import the External libraries in Node.js. The
result returned by require() is stored in a variable which is used to invoke
the functions using the dot notation.
res.write('Hello World!');
res.end();
}).listen(3000);Run this program from the command line and see the
output in the browser window. This program prints Hello World on the
browser when the browser sends a request through http://localhost:3000/.
19. What is the most popular Node.js framework used these days?
An event loop that listens for event triggers and calls the
corresponding event handler for that event.
Streams are a type of data-handling method and are used to read or write
input into output sequentially. Streams are used to handle reading/writing
files or exchanging information in an efficient way. The stream module
provides an API for implementing the stream interface. Examples of the
stream object in Node.js can be a request to an HTTP server and
process.stdout are both stream instances.
The crypto module is used for encrypting, decrypting, or hashing any type
of data. This encryption and decryption basically help to secure and add a
layer of authentication to the data. The main use case of the crypto
module is to convert the plain readable text to an encrypted format and
decrypt it when required.
Callback hell is an issue caused due to a nested callback. This causes the
code to look like a pyramid and makes it unable to read To overcome this
situation we use promises.
setTimeout() method
setImmediate() method
setInterval() method
Both these methods are used to create new child processes the only
difference between them is that spawn() method creates a new function
that Node runs from the command line whereas fork() function creates an
instance of the existing fork() method and creates multiple workers to
perform on the same task.
Using async/await()
Using promises
Using generators
Fork(): It creates a new child process from the master. The isMaster
returns true if the current process is master or else false.
Types of Stream:
Readable stream: It is the stream from where you can receive and
read the data in an ordered fashion. However, you are not allowed
to send anything. For example, fs.createReadStream() lets us read
the contents of a file.
The package used for file uploading in Node.js is Multer. The file can be
uploaded to the server using this module. There are other modules in the
market but Multer is very popular when it comes to file uploading. Multer
is a node.js middleware that is used for handling multipart/form-data,
which is a mostly used library for uploading files.
Step 1: Save a file as index.js and paste the below code inside the file.
JavaScript
console.log(arguments) ;
node index.js
Net Module: Net Module in node.js is used for the creation of both
client and server. Similar to DNS Module this module also provides
an asynchronous network wrapper.
The Tracing Objects are used for a set of categories to enable and disable
the tracing. When tracing events are created then tracing objects is
disabled by calling tracing.enable() method and then categories are added
to the set of enabled trace and can be accessed by calling
tracing.categories.