Node JS Interview Questions And Answers

Node-JS.jpg

Q: What's the first-class function in Javascript?

When functions are often treated like all other variables then those functions are first-class functions. There are many other programming languages, for instance, scala, Haskell, etc which follow this including JS. Now due to this function is often passed as a param to a different function(callback) or a function can return another function(higher-order function). map,  filter are higher-order functions which are popularly used.

Q: What's node.js?

Node.js may be Server-side scripting that's want to build scalable programs. Its multiple benefits over other server-side languages, the prominent being non-blocking I/O.

Q: Why use Node.js?

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

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

Q: Why is Node.js Single-threaded?

Node.js is single-threaded for async processing. By doing async processing on a single thread under typical web loads, more performance and scalability are often achieved rather than the standard thread-based implementation.

Q: What's the advantage of using node.js?

  • It provides a simple thanks to building scalable network programs
  • Generally fast
  • Great concurrency
  • Asynchronous everything
  • Almost never blocks

Q: What's the control flow function?

A generic piece of code that runs in between several asynchronous function calls is understood as a control flow function.

Q: What is REPL? What purpose is it used for?

REPL stands for (READ, EVAL, PRINT, LOOP). Node js comes with a bundled REPL environment. which enables the straightforward creation of CLI (Command Line Interface) applications.

Q: How does Node.js handle child threads?

Node.js, in its essence, may be a single thread process. It doesn't reveal child threads and thread management methods to the developer. Technically, Node.js does spawn child threads for tasks like asynchronous I/O, but these run behind the scenes and don't execute any application JavaScript code, nor block the most event loop.

If threading support is desired during a Node.js application, there are tools available to enable it, like the Child Process module. In fact, Node.js 12 has experimental support for the threads.

Q: Explain Node.js web application architecture?

A web application distinguishes into 4 layers:

Client Layer: The Client layer contains web browsers, mobile browsers, or applications that may make an HTTP request to the online server.

Server Layer: The Server layer contains the online server which may intercept the request made by clients and pass them the response.

Business Layer: The business layer contains an application server that is employed by the online server to try to require processing. This layer interacts with the info layer via a database or some external programs.

Data Layer: the info layer contains databases or any source of knowledge.

Q: What is npm? what's the most useful feature of npm?

npm stands for Node Package Manager. Following are the 2 main functionalities of npm: Online repositories for node.js packages or modules which are searchable on search.nodejs.org

Command-line utility to put them in packages, do version management, and dependency management of Node.js packages.

Q: What are the streams in Node.js?

The Streams are the objects that ease you to read data from a source and write data to a destination. There are four sorts of streams in Node.js:

Readable: This stream is employed for reading operations.

Writable: This stream is employed for write operations.

Duplex: This stream is often used for both reading and writing operations.

Transform: it's a kind of duplex stream where the output computes consistent with the input.

Q: What are node.js buffers?

In general, buffers are temporary memory that's mainly employed by streams to carry on to some data until consumed. Buffers are introduced with additional use cases than JavaScript’s Uint8Array and mainly want to represent a fixed-length sequence of bytes. This also holds legacy encodings like ASCII, utf-8, etc. it's a fixed(non-resizable) allocated memory outside the v8.

Also Read: Angular Interview Questions And Answers