# Node Js Asked Questions

what is node js ? Node.js is an open-source JavaScript runtime environment that allows developers to run JavaScript code on the server-side. It uses the V8 JavaScript engine, providing high performance and non-blocking I/O operations. Node.js is commonly used for building scalable network applications, web servers, and APIs, as well as for backend development Explain the steps how “Control Flow” controls the functions calls? Control the order of execution Collect data Limit concurrency Call the following step in the program.

What are some commonly used timing features of Node.js? setTimeout/clearTimeout – This is used to implement delays in code execution. setInterval/clearInterval – This is used to run a code block multiple times. setImmediate/clearImmediate – Any function passed as the setImmediate() argument is a callback that's executed in the next iteration of the event loop. process.nextTick – Both setImmediate and process.nextTick appear to be doing the same thing; however, you may prefer one over the other depending on your callback’s urgency

What is middleware? Middleware comes in between your request and business logic. It is mainly used to capture logs and enable rate limit, routing, authentication, basically whatever that is not a part of business logic. There are third-party middleware also such as body-parser and you can write your own middleware for a specific use case. Buffer buffers is a temporary memory that is mainly used by stream to hold on to some data until consumed. Buffers are introduced with additional use cases than JavaScript’s Unit8Array and are mainly used to represent a fixed-length sequence of bytes. This also supports legacy encodings like ASCII, utf-8, etc. It is a fixed(non-resizable) allocated memory outside the v8.

Node js architecture feature Node.js is a virtual machine that uses JavaScript as its scripting language and runs Chrome’s V8 JavaScript engine. Basically, Node.js is based on an event-driven architecture where I/O runs asynchronously making it lightweight and efficient. It is being used in developing desktop applications as well with a popular framework called electron as it provides API to access OS-level features such as file system, network, etc.

Explain stream in Nodejs along with its various types? Streams in Node.js are the collection of data similar to arrays and strings. They are objects using which you can read data from a source or write data to a destination in a continuous manner. It might not be available at once and need not to have fit in the memory. These streams are especially useful for reading and processing a large set of data. In Node.js, there are four fundamental types of streams: o Readable: Used for reading large chunks of data from the source. o Writeable: Use for writing large chunks of data to the destination. o Duplex: Used for both the functions; read and write. o Transform: It is a duplex stream that is used for modifying the dat

Asynchronous I/O What do you mean by Asynchronous API? All APIs of Node.js library are aynchronous that is non-blocking. It essentially means a Node.js based server never waits for a API to return data. Server moves to next API after calling it and a notification mechanism of Events of Node.js helps server to get response from the previous API cal

Single threaded Yes! Node uses a single threaded model with event looping.s Explain libuv? Libuv is a multi-platform support library of Node.js which majorly is used for asynchronous I/O. It was primarily developed for Node.js, with time it is popularly practiced with other systems like as Luvit, pyuv, Julia, etc. Libuv is basically an abstraction around libev/ IOCP depending on the platform, providing users an API based on libev. A few of the important features of libuv are: o Full-featured event loop backed o File system events o Asynchronous file & file system operations o Asynchronous TCP & UDP sockets o Child processes

What is difference between synchronous and asynchronous method of fs module? Every method in fs module has synchronous as well as asynchronous form. Asynchronous methods take a last parameter as completion function callback and first parameter of the callback function is error. It is preferred to use asynchronous method instead of synchronous method as former never block the program execution where the latter one does.

What is node js benifits Why use Node.js?

Node.js makes building scalable network programs easy. Some of its advantages include:

It is generally fast It rarely blocks It offers a unified programming language and data type Everything is asynchronous It yields great concurrency

What Is EventEmitter In NodeJs? Events module in Node.js allows us to create and handle custom events. The Event module contains “EventEmitter” class which can be used to raise and handle custom events. It is accessible via the following code. When an EventEmitter instance encounters an error, it emits an “error” event. When a new listener gets added, it fires a “newListener” event and when a listener gets removed, it fires a “removeListener” event. EventEmitter provides multiple properties like “on” and “emit”. The “on” property is used to bind a function to the event and “emit” is used to fire an event. .

Name the types of API functions in Node? There are two types of functions in Node.js.

1. Blocking functions - In a blocking operation, all other code is blocked from executing until an I/O event that is being waited on occurs. Blocking functions execute synchronously.
    
2. Non-blocking functions - In a non-blocking operation, multiple I/O calls can be performed without the execution of the program being halted. Non-blocking functions execute asynchronously.
    

What is meant by thread pool? A thread pool is a collection of worker threads that efficiently execute asynchronous callbacks on behalf of the application. The thread pool is primarily used to reduce the number of application threads and provide management of the worker threads.

Node.js has a built-in module, called "Events", where you can create-, fire-, and listen for- your own events. To include the built-in Events module use the require() method. In addition, all event properties and methods are an instance of an EventEmitter object. https To make Node.js act as an HTTPS server. path To handle file paths events To handle events fs To handle the file system http To make Node.js act as an HTTP server https To make Node.js act as an HTTPS server

Required function Node.js Module System In Node.js each file is treated as a separate module. Modules provide us a way of re- using existing code. The require Function We can re-use existing code by using the Node built-in require() function. This function imports code from another module.

Global object Node.js Global Object In Node, we have a global object that we can always access. Features that we expect to be available everywhere live in this global object. For example, to have some code execute after 5 seconds we can use either global.setTimeout or just setTimeout . The global keyword is optional. setTimeout(() =&gt; { console.log('hello'); }, 5000); Probably the most famous global is global.console.log which we write as just console.log

What is routing node js?

Routing in Node refers to the process of determining how an application responds to client requests to different endpoints (URLs). In a web application, these endpoints typically correspond to different pages or functionalities within the application.

Event driven What is event-driven in NodeJS? Event Driven Programming

Node. js uses event driven programming. It means as soon as Node starts its server, it simply initiates its variables, declares functions and then simply waits for event to occur.

event emitors What is the use of event emitter? EventEmitter is a class in node. js that is responsible for handling the events created using the 'events' module in node. js. Events are created to make custom operations while a set of operations is performed

What is event loop in NodeJS?

An event loop is an endless loop, which waits for tasks, executes them, and then sleeps until it receives more tasks. The event loop executes tasks from the event queue only when the call stack is empty i.e. there is no ongoing task. The event loop allows us to use callbacks and promise

Built in modul Path htttp https fs Repl PL in Node.js stands for Read, Eval, Print, and Loop, which further means evaluating code on the go. Module export import Npm Node modules

What is req res next in NodeJS? Middleware functions are functions that have access to the request object ( req ), the response object ( res ), and the next middleware function in the application's request-response cycle. The next middleware function is commonly denoted by a variable named next

Es6 What is ES6? ES6 stands for ECMAScript 6. ECMAScript was created to standardize JavaScript, and ES6 is the 6th version of ECMAScript, it was published in 2015, and is also known as ECMAScript 2015

Npm init Npm start Npm init -y Args

What is a cluster in node JS?

The cluster module allows you to create copies of your node process that each run your server code side by side in parallel. The way this works is when you type: node server. js to start your node application, the main node process is created. Node calls this the master process inside of the cluster module Sharding is a method for distributing data across multiple machines. MongoDB uses sharding to support deployments with very large data sets and high throughput operations. Database systems with large data sets or high throughput applications can challenge the capacity of a single server

js Utility Module: The Util module in node. js provides access to various utility functions. Syntax: const util = require('util');

What is chain in Nodejs? Promise chaining: Promise chaining is a syntax that allows you to chain together multiple asynchronous tasks in a specific order. This is great for complex code where one asynchronous task needs to be performed after the completion of a different asynchronous task

Duplex

What is child process and parent process?

A parent process uses fork to create a new child process. The child process is a copy of the parent. After fork, both parent and child executes the same program but in separate processes. exec. Replaces the program executed by a process.
