Question:- What are the advantages of Node.js?
Answer:- Following are the main advantages of Node.js: • Node.js is asynchronous and event-driven. All API?s of Node.js library are non-blocking, and its server doesnt wait for an API to return data. It moves to the next API after calling it, and a notification mechanism of Events of Node.js responds to the server from the previous API call. • Node.js is very fast because it builds on Google Chrome?s V8 JavaScript engine. Its library is very fast in code execution. • Node.js is single threaded but highly scalable. • Node.js provides a facility of no buffering. Its application never buffers any data. It outputs the data in chunks.
Question:- Explain Node.js web application architecture?
Answer:- A web application distinguishes into 4 layers: • Client Layer: The Client layer contains web browsers, mobile browsers or applications which can make an HTTP request to the web server. • Server Layer: The Server layer contains the Web server which can intercept the request made by clients and pass them the response. • Business Layer: The business layer contains application server which is utilized by the web server to do required processing. This layer interacts with the data layer via database or some external programs. • Data Layer: The Data layer contains databases or any source of data.
Question:- What do you understand by the term I/O?
Answer:- The term I/O stands for input and output. It is used to access anything outside of your application. The I/O describes any program, operation, or device that transfers data to or from a medium or another medium. This medium can be a physical device, network, or files within a system. I/O is loaded into the machine memory to run the program once the application starts.
Question:- How many types of API functions are available in Node.js?
Answer:- There are two types of API functions in Node.js: • Asynchronous, Non-blocking functions • Synchronous, Blocking functions
Question:- What do you understand by the first class function in JavaScript?
Answer:- When functions are treated like any other variable, then those functions are called first-class functions. Apart from JavaScript, many other programming languages, such as Scala, Haskell, etc. follow this pattern. The first class functions can be passed as a param to another function (callback), or a function can return another function (higher-order function). Some examples of higher-order functions that are popularly used are map() and filter().
Question:- Explain the working of Node.js?
Answer:- The workflow of a Node.js web server typically looks like the following diagram. Let us see the flow of operations in detail: • According to the above diagram, the clients send requests to the webserver to interact with the web application. These requests can be non-blocking or blocking and used for querying the data, deleting data, or updating the data. • js receives the incoming requests and adds those to the Event Queue. • After this step, the requests are passed one by one through the Event Loop. It checks if the requests are simple enough not to require any external resources. • The event loop then processes the simple requests (non-blocking operations), such as I/O Polling, and returns the responses to the corresponding clients. • A single thread from the Thread Pool is assigned to a single complex request. This thread is responsible for completing a particular blocking request by accessing external resources, such as computation, database, file system, etc. • Once the task is completed, the response is sent to the Event Loop that sends that response back to the client.
Question:- How can you manage the packages in your Node.js project?
Answer:- We can manage the packages in our Node.js project by using several package installers and their configuration file accordingly. Most of them use npm or yarn. The npm and yarn both provide almost all libraries of JavaScript with extended features of controlling environment-specific configurations. We can use package.json and package-lock.json to maintain versions of libs being installed in a project. So, there is no issue in porting that app to a different environment.
Question:- Why is Node.js Single-threaded?
Answer:- Node.js is a single-threaded application with event looping for async processing. The biggest advantage of doing async processing on a single thread under typical web loads is that you can achieve more performance and scalability than the typical thread-based implementation.
Question:- What do you understand by callback hell in Node.js?
Answer:- Callback hell is a phenomenon that creates a lot of problems for a JavaScript developer when he tries to execute multiple asynchronous operations one after the other. A function is called an asynchronous function when some external activity must complete before processing a result. It is called asynchronous because there is an unpredictable amount of time before a result becomes available. These functions require a callback function to handle errors and process the result.
Question:- How is Node.js better than other most popular frameworks?
Answer:- Based on the following criteria, we can say that Node.js is better than other most popular frameworks: • js makes development simple because of its non-blocking I/O and even-based model. This simplicity results in short response time and concurrent processing, unlike other frameworks where developers use thread management. • js runs on a chrome V8 engine which is written in C++. It enhances its performance highly with constant improvement. • With Node.js, we will use JavaScript in both the frontend and backend development that will be much faster. • js provides ample libraries so that we dont need to reinvent the wheel.
Question:- In which types of applications is Node.js most frequently used?
Answer:- Node.js is most frequently and widely used in the following applications: • Internet of Things • Real-time collaboration tools • Real-time chats • Complex SPAs (Single-Page Applications) • Streaming applications • Microservices architecture etc.
Question:-
Answer:-
Question:- What are some commonly used timing features of Node.js?
Answer:- Following is a list of some commonly used timing features of Node.js: • setTimeout/clearTimeout: This timing feature of Node.js is used to implement delays in the code execution. • setInterval/clearInterval: The setInterval or clearInterval timing feature is used to run a code block multiple times in the application. • setImmediate/clearImmediate: This timing feature of Node.js is used to set the execution of the code at the end of the event loop cycle. • nextTick: This timing feature sets the execution of code at the beginning of the next event loop cycle.
Question:- What do you understand by the term fork in Node.js?
Answer:- Generally, a fork is used to spawn child processes. In Node.js, it is used to create a new instance of the V8 engine to run multiple workers to execute the code.
