Quick Contact


    Q11-: Explain the benefits of Node.js?

    There are several benefits that streams bring to node.js which make them very important -:

    • It is memory efficient because with streams you only works with chunks of data at a time and not all of the data that streams represents node.js processes have a maximum memory limit of just under 2 gigabytes, so if you want to read 20 gigabyte file into memory you would quickly run out of memory and process would crash but with streams you don’t need the entire file into a memory instead you can handle chunks of the file in order to get around hitting the maximum memory limit it’s this approach that makes streams memory efficient as opposed to buffering all the data in memory at same time.
    • Handle data as it arrives-: Streams are also able to begin handling data as soon as the first piece of it arrives this means that streams are also time efficient.
    • In example of opening 20 gigabyte file you would need to wait until all of the data had been loaded before you could even start working with that but with streams you are able to start working with data as soon as the first chunk arrives and then you will be able to work on the next chunk as soon as that pieces are made available.

    • Finally, Streams are also composable meaning that they can be connected too and combined with other streams. The output of one stream can be used as input for another stream, allowing us to combine streams into pipeline through which data can flow between the various streams.
    Q12-: Explain different types of Streams?

    There are four main types of streams in Node.js-:

    • Readable-:

      First type is a readable stream which represents a source of input. You read data from a readable stream.

    • Writable streams-:

      These streams represent a destination you write data too. Writeable streams are sometimes referred to as sync because it is end destination for streaming data. It differs from a readable stream in that you can’t consume data from a writeable stream. You only push data to writeable stream

    • Duplex-:

      Things get little bit complicated when we get to duplex streams. Duplex stream implements both readable and writeable interface. Duplex Streams can both receive data as well as produce data. For example like TCP socket where data can flow in both directions. You can receive data from an open TCP connection as well as write data too from other end of TCP connection.

    • Transform-:

      Transform stream is type of duplex stream in which data passing through stream is altered. The output will be different from the input. You can write data to transform stream and also read data from it. After data has been transformed

    • PassThrough-:

      It is final type of Stream. It is special type of transform stream which donot alter the data passing through it.

    Q13-: Write about Stream events?

    In stream events Streams are the instance of Event Emitter-:

    -Event Emitter

    Event Emitter objects in node.js are used to emit and respond to events asynchronously as such streams invent events of their own which can be used to read and write data manage the stream state as well as handle errors. While it’s important to understand some of the events that streams can produce to be able to understand what’s happening at their low levels.

    -Not recommended for interaction via events with streams-

    Not recommended for interaction via events with streams- Node.js is changed now. Nowadays recommended way to consume and interact with streams is by using pipe and pipeline methods which will consume the streams and handle their underlying events for you.

    -Stream Events are useful for fine-grained control over streams-

    As there are some cases where very fine grain control is needed over how a stream is consumed or how it works. Stream events are very handy for that if you want to run custom code when stream ends or begins or when something within lifecycle or stream happens.

    Q14-: Difference between JavaScript and NodeJS.
    JavaScript Node JS
    JS is a programming language. Node.js is runtime environment as well as interpreter for JavaScript.
    Used in web application for client-side activity. Used for accessing or performing any non-blocking operation of OS.
    Running Engine in JS are Spider Monkey (Firefox), JavaScript Core (Safari), V8 (Google Chrome), etc. V8 engine (Google Chrome) used Node JS
    JavaScript can only be run in browser. It can run outside the browser.
    It is used in frontend development. NodeJS is used in server-side development.
    It is ECMA script upgraded version which uses Chrome V8 engine. It is written in C++. Nodejs is written in C, C++ and JavaScript.
    JavaScript can add HTML and capable to play with DOM. Node.js doesn’t have capability to add HTML tags.
    Q15-: What is error-first callback in Node.js?

    There are only two rules for defining an error-first callback. First rule or first argument is reserved for an error object.

    		Var myPost = new Post{{title: ‘’}};
    		Mypost.save{function(err, instance){
    		If (err) {
    		     //handle error and return
    		}
    		//go ahead with “myinstance”
    		}
    		};
    	

    As function has two arguments- (err, instance), so callback means first argument is reserved for error object. If an error occurs it will be returned by “err” argument. Now first argument is reserved for any successful reserved data. If no error occurred then “err” is said to null. In each successful data then shown in second argument.

    Q16-: What do you understand by Reactor Pattern in Node.js?

    It is basically a concept of Non-Blocking input output operation.

    Reactor pattern provides a handler in case of node.js called it as Callback function that is associated with each input output operation.

    As soon as input output request is generated then it is submitted to demultiplexer then this demultiplexer is notification interface which is capable of handling concurrency of logging input output mode.

    Reactor pattern in Node.js also helps in collecting each and every request in form of any event and place each event in queue which results in event queue.

    Q17-: Explain Front-end and Back-end Development?
    Frontend Development

    It uses mark up as well as web languages like HTML, CSS and JavaScript. It is based on asynchronous requests and AJAX. It has better accessibility. It is better used for SEO.

    Backend Development

    It uses programming or scripting language like python, ruby, perl etc. It is based on Server side architecture. It has enhanced security. It is usually used for Backup.

    Q18-: Explain Libuv?

    It is library used in Node.js and it is multi-platform support which is mostly used for asynchronous I/O.

    -It has high efficient event loop so you can say it has full featured event loop backed with it. It has solution for input output blocking operations. It has great performance by combining asynchronous event loop and threadpool for no-blocking input output and blocking I/O operations.

    -It has file system events and child processes.

    -It has asynchronous file system and Asynchronous TCP, UDP sockets.

    Q19-: Explain concept of URL module?

    URL module provides various utilities for URL resolution as well as its parsing.

    -URL module is built-in module which helps in splitting web address into readable format.

    To include URL modules in Node.jss project we use require method

    		Var url = require (‘url’);
    		There are more variables and logs return syntax as below-:
    		Var adrs = “//http address is written here”;
    		Var q = url.parse(adr, true);
    		Console.log (q.host); //returns ‘localhost: 8082’
    		Console.log (q.pathname); //returns ‘/default.htm’
    		Console.log (q.search); //returns ‘?year= 2021, month: ‘’’
    		Console.log (qdata.month); //returns ‘//month is written here’
    	
    Q20-: Explain working of Control Flow Function?

    Control flow controls the request of execution, it gathers information, it helps in breakpoint simultaneousness etc.

    Control function is a code that executed between various asynchronous function. Following diagram tells how control flow helps in Node.js

    Node JS Question Answers

    Copyright 1999- Ducat Creative, All rights reserved.