Explore topic-wise InterviewSolutions in .

This section includes InterviewSolutions, each offering curated multiple-choice questions to sharpen your knowledge and support exam preparation. Choose a topic below to get started.

51.

Mention types of streams?

Answer»

The following are the types of streams in Node.Js:

1) Readable Streams: A stream where you can recieve data but cannot send it.  When you push data into a readable stream , it is buffered, until customer starts to read the data

    Example: HTTP REQUESTS to the server. Based on the HTTP request, server sends HTTP response to the client which is a readable stream. Another example is RSS FEED posted by remote SERVERS on the HTTP clients are readonly streams.

Module used: fs.createReadStream

2) Writable Streams: A stream where you can send the data but not recieve  from it.

    Example: user entered data on HTTP clients go as HTTP Responses to the server where data is written.

Module used: fs.createWriteStream()

3) Duplex Streams: Streams that are both readable and writable.

Example: TCP sockets

Module used: net.socket

4) Transform Streams: A type of duplex streams where output is in someway related to the input. LIKE duplex streams, Transform streams also implement both Readable and Writable interfaces.

52.

What are streams?

Answer»

Streams are a way handling following:

  1. reading/ writing files
  2. network communications
  3. any kind of end-to-end information exchange.

It is the movement of data from one point to another.

When a program is supposed to read a FILE consisting of single page(three to four lines), it will be initially read into memory from start to FINISH and then starts processing. If the file is an e-book consisting of 500+ pages , then it takes lot of storage SPACE and TIME to be LOADED into memory, before started processing. This is where Streams make a difference.

Using streams, you read it piece by piece , processing its content without keeping it in memory.

The following are the advantages of streams

  1. Memory Efficiency: You don’t load large amounts data before processing it, It just reads a block of data and process it immediately and continues the same till end of the file.
  2. Time Efficiency: It takes way less time to process the data as soon as you have it without having to wait for whole data to be loaded or available.

The following code statement refer to stream module

const stream = require(‘Stream’);
53.

Name the type of applications where you can use Node.js?

Answer»
  1. I/O BOUND applications.
    It can be anything ranging from reading/writing local FILES to making an HTTP request to  an API. 
  2. DATA streaming applications.
    Stock broker trading applications – takes those prices and send them in realtime to    customers or to other application for further processing.
  3. Data intensive Real time applications. Like Chat applications like Whatsapp, facebook,  Linkedin
  4. JSON API based applications like Twitter
  5. Single page applications like Angular applications.
    Angular uses npm (NodeJS package manager) for accessing its libraries. For speeding  up angular development you need CLI (Command level Interface)which INTURN REQUIRES  node and npm.
54.

Name any three features of Node.js?

Answer»

Here is the list of important features of Node.JS

  • No buffering: Node.js applications never buffer any data(ASCII). These applications simply output data in chunks.
  • Extremely Fast: Node.js is built on Google Chrome’s Javascript V8 Engine so its library is very fast in code execution. As you are aware Javascript is used to built CLIENT side applications which is also built on V8 engine, so this makes Node JS applications faster.
  • I/O is Asynchronous and Event DRIVEN: All APIs of Node.js library are asynchronous i.e. non-blocking. So a Node.js based server never waits for an API to return data. The server moves to the next API after calling it and a notification MECHANISM of Events of Node.js helps the server to get a response from the previous API call. It is also a reason that makes it is very fast
  • Highly Scalable: Node.js is highly scalable because event mechanism helps the server to respond in a non-blocking way.
55.

Who uses Node.js?

Answer»

Microsoft, Paypal, Uber

  • Microsoft Visual Studio code uses Node.Js as a platform.
  • Paypal migrated their application from Java BACKEND to Node.JS and achieved benefits like INCREASED productivity and lesser lines of written code and fewer files are constructed.
  • Uber was among the first to put Node.js into full production. Its mobile application process needed high scalability option due to increasing demand of USERS. Uber’s Despatching system runs on Node.JS. Uber achieved benefits like faster code deployment and effective error analysis(WITHOUT restart) and high scalability.
56.

Name the applications where you cannot use Node.js?

Answer»

It is not advisable to use Node.js for CPU intensive applications

Because node.js is designed AROUND using a single thread very EFFICIENTLY. Its event based model dispatches code fragments when specific events occur. Those code fragments are supposed to execute very quickly and then return CONTROL to node.js, which then dispatches the NEXT event.

If one of those code fragments PERFORMS a long running task, then no more events will be dispatched and the whole system appears to hang.

57.

What is Node.js?

Answer»
  1.  A server side platform built on Google Chrome’s JAVASCRIPT V8 Engine.
  2. Open source, CROSS platform runtime environment for developing server side and NETWORKING APPLICATIONS. Node.js runs on various platforms like Windows, Linux, MacOs.

For those coming from Java development background , here is the ANALOGY.