Top 100+ Node.js Interview Questions And Answers
Question 1. What Is Node.Js?
Answer :
Node.Js is a web application framework built on Google Chrome's JavaScript Engine(V8 Engine).
Node.Js comes with runtime environment on which a Javascript based script may be interpreted and completed (It is analogus to JVM to JAVA byte code). This runtime allows to execute a JavaScript code on any gadget outside a browser. Because of this runtime of Node.Js, JavaScript is now may be finished on server as well.
Node.Js additionally affords a rich library of numerous javascript modules which eases the developement of internet application the use of Node.Js to super extents.
Node.Js = Runtime Environment + JavaScript Library
Question 2. What Do You Mean By Asynchronous Api?
Answer :
All APIs of Node.Js library are aynchronous that is non-blockading. It essentially manner a Node.Js based totally server by no means waits for a API to return statistics. Server movements to subsequent API after calling it and a notification mechanism of Events of Node.Js enables server to get response from the previous API name.
HTML 5 Interview Questions
Question three. What Are The Benefits Of Using Node.Js?
Answer :
Following are important blessings of the usage of Node.Js
Aynchronous and Event Driven All APIs of Node.Js library are aynchronous this is non-blockading. It essentially approach a Node.Js based totally server by no means waits for a API to go back facts. Server moves to next API after calling it and a notification mechanism of Events of Node.Js facilitates server to get reaction from the preceding API name.
Very Fast Being built on Google Chrome's V8 JavaScript Engine, Node.Js library may be very speedy in code execution.
Single Threaded but incredibly Scalable - Node.Js uses a single threaded version with occasion looping. Event mechanism enables server to respond in a non-bloking ways and makes server especially scalable as adversarial to standard servers which create confined threads to deal with requests. Node.Js uses a single threaded application and equal application can services tons large number of requests than conventional server like Apache HTTP Server.
No Buffering - Node.Js packages in no way buffer any records. These packages in reality output the statistics in chunks.
Question 4. Is It Free To Use Node.Js?
Answer :
Yes! Node.Js is released underneath the MIT license and is unfastened to use.
HTML five Tutorial
Question 5. Is Node A Single Threaded Application?
Answer :
Yes! Node uses a unmarried threaded version with event looping.
Java Script Interview Questions
Question 6. What Is Repl In Context Of Node?
Answer :
REPL stands for Read Eval Print Loop and it represents a pc environment like a window console or unix/linux shell wherein a command is entered and system responds with an output. Node.Js or Node comes bundled with a REPL environment. It performs the subsequent favored obligations.
Read - Reads person's enter, parse the enter into JavaScript statistics-shape and stores in memory.
Eval - Takes and evaluates the data shape
Print - Prints the end result
Loop - Loops the above command till person press ctrl-c twice.
Question 7. What Is The Difference Of Using Var And Not Using Var In Repl While Dealing With Variables?
Answer :
Use variables to shop values and print later. If var key-word is not used then fee is stored inside the variable and printed. Wheras if var key-word is used then cost is stored however no longer revealed. You can use each variables later.
Java Script Tutorial PHP Interview Questions
Question eight. What Is The Use Of Underscore Variable In Repl?
Answer :
Use _ to get the closing result.
C:Nodejs_WorkSpace>node
> var x = 10
undefined
> var y = 20
undefined
> x + y
30
> var sum = _
undefined
> console.Log(sum)
30
undefined
>
Question nine. What Is Npm?
Answer :
npm stands for Node Package Manager. Npm provides following major functionalities:
Online repositories for node.Js programs/modules that are searchable on search.Nodejs.Org
Command line application to install packages, do version management and dependency control of Node.Js packages.
Ruby on Rails Interview Questions
Question 10. What Is Global Installation Of Dependencies?
Answer :
Globally installed programs/dependencies are stored in <user-directory>/npm directory. Such dependencies can be utilized in CLI (Command Line Interface) feature of any node.Js but can not be imported the use of require() in Node utility without delay. To set up a Node assignment globally use -g flag.
C:Nodejs_WorkSpace>npm set up express -g
PHP Tutorial
Question eleven. What Is Local Installation Of Dependencies?
Answer :
By default, npm installs any dependency in the neighborhood mode. Here neighborhood mode refers back to the package deal set up in node_modules directory mendacity in the folder in which Node software is gift. Locally deployed programs are reachable through require(). To deploy a Node project domestically following is the syntax.
C:Nodejs_WorkSpace>npm deploy express
Angular JS Interview Questions
Question 12. How To Check The Already Installed Dependencies Which Are Globally Installed Using Npm?
Answer :
Use the following command:
C:Nodejs_WorkSpace>npm ls -g
HTML five Interview Questions
Question thirteen. What Is Package.Json?
Answer :
package deal.Json is gift inside the root listing of any Node software/module and is used to outline the residences of a package deal.
Ruby on Rails Tutorial
Question 14. Name Some Of The Attributes Of Package.Json?
Answer :
Following are the attributes of Package.Json
call - name of the package
version - version of the package
description - description of the package deal
homepage - homepage of the package
creator - creator of the bundle
members - name of the contributors to the package deal
dependencies - listing of dependencies. Npm routinely installs all of the dependencies stated right here inside the node_module folder of the package deal.
Repository - repository kind and url of the package
major - access factor of the package deal
key phrases - keywords
Question 15. How To Uninstall A Dependency Using Npm?
Answer :
Use following command to uninstall a module.
C:Nodejs_WorkSpace>npm uninstall dependency-call
Ruby Interview Questions
Question 16. How To Update A Dependency Using Npm?
Answer :
Update bundle.Json and alternate the version of the dependency which to be updated and run the following command.
C:Nodejs_WorkSpace>npm update
Ext JS Tutorial
Question 17. What Is Callback?
Answer :
Callback is an asynchronous equivalent for a function. A callback feature is called on the crowning glory of a given challenge. Node makes heavy use of callbacks. All APIs of Node are written is this kind of way that they helps callbacks. For instance, a characteristic to read a document may also start analyzing document and return the control to execution environment immidiately in order that next practise may be achieved. Once file I/O is complete, it'll call the callback characteristic while passing the callback characteristic, the content of the document as parameter. So there may be no blocking off or watch for File I/O. This makes Node.Js relatively scalable, as it can procedure high number of request without waiting for any feature to go back end result.
Ext JS Interview Questions
Question 18. What Is A Blocking Code?
Answer :
If utility has to look ahead to some I/O operation so as to finish its execution any further then the code answerable for ready is referred to as blocking code.
Java Script Interview Questions
Question 19. How Node Prevents Blocking Code?
Answer :
By supplying callback function. Callback characteristic gets known as whenever corresponding event caused.
Koa.Js Tutorial
Question 20. What Is Event Loop?
Answer :
Node js is a single threaded software but it support concurrency through concept of event and callbacks. As every API of Node js are asynchronous and being a single thread, it uses async feature calls to preserve the concurrency. Node makes use of observer pattern. Node thread maintains an event loop and each time any undertaking get completed, it fires the corresponding occasion which alerts the occasion listener function to get accomplished.
Java Abstraction Interview Questions
Question 21. What Is Event Emmitter?
Answer :
EventEmitter elegance lies in activities module. It is accessibly through following syntax:
//import events module
var events = require('occasions');
//create an eventEmitter item
var eventEmitter = new occasions.EventEmitter();
When an EventEmitter instance faces any errors, it emits an 'error' event. When new listener is added, 'newListener' event is fired and whilst a listener is removed, 'removeListener' event is fired.
EventEmitter gives more than one houses like on and emit. On belongings is used to bind a feature with the event and emit is used to fireplace an event.
Question 22. What Is Purpose Of Buffer Class In Node?
Answer :
Buffer class is a global class and may be accessed in utility without uploading buffer module. A Buffer is a form of an array of integers and corresponds to a raw reminiscence allocation outside the V8 heap. A Buffer can't be resized.
Ruby on Rails 2.1 Tutorial
Question 23. What Is Piping In Node?
Answer :
Piping is a mechanism to attach output of one stream to some other move. It is commonly used to get facts from one flow and to pass output of that flow to another circulation. There is no restrict on piping operations. Consider the above example, where we've got study test.Txt the use of readerStream and write test1.Txt the use of writerStream. Now we will use the piping to simplify our operation or analyzing from one file and writing to every other record.
Koa.Js Interview Questions
Question 24. Which Module Is Used For File Based Operations?
Answer :
fs module is used for record based operations.
Var fs = require("fs")
PHP Interview Questions
Question 25. Which Module Is Used For Buffer Based Operations?
Answer :
buffer module is used for buffer based operations.
Var buffer = require("buffer")
Backbone.Js Tutorial
Question 26. Which Module Is Used For Web Based Operations?
Answer :
http module is used for internet based operations.
Var http = require("http")
Backbone.Js Interview Questions
Question 27. What Is Difference Between Synchronous And Asynchronous Method Of Fs Module?
Answer :
Every technique in fs module have synchronous as well as asynchronous shape. Asynchronous methods takes a last parameter as finishing touch characteristic callback and first parameter of the callback feature is error. It is desired to apply asynchronous technique rather than synchronous technique as former by no means block the program execution in which the latter one does.
Ruby on Rails Interview Questions
Question 28. Name Some Of The Flags Used In Read/write Operation On Files.
Answer :
flags for examine/write operations are following:
r - Open document for reading. An exception takes place if the report does not exist.
R+ - Open document for reading and writing. An exception happens if the record does now not exist.
Rs - Open report for studying in synchronous mode. Instructs the running gadget to pass the local report machine cache. This is more often than not beneficial for starting files on NFS mounts as it lets in you to bypass the potentially stale neighborhood cache. It has a very actual impact on I/O overall performance so don't use this flag except you need it. Note that this does not turn fs.Open() right into a synchronous blockading call. If that's what you need then you definately have to be using fs.OpenSync()
rs+ - Open document for analyzing and writing, telling the OS to open it synchronously. See notes for 'rs' about the use of this with warning.
W - Open document for writing. The file is created (if it does not exist) or truncated (if it exists).
Wx - Like 'w' but fails if course exists.
W+ - Open file for reading and writing. The file is created (if it does now not exist) or truncated (if it exists).
Wx+ - Like 'w+' but fails if route exists.
A - Open report for appending. The report is created if it does now not exist.
Ax - Like 'a' however fails if route exists.
A+ - Open report for analyzing and appending. The record is created if it does no longer exist.
Ax+' - Like 'a+' however fails if direction exists.
Phonegap Tutorial
Question 29. What Are Streams?
Answer :
Streams are items that can help you examine records from a supply or write statistics to a vacation spot in continous style.
D3.Js Interview Questions
Question 30. How Many Types Of Streams Are Present In Node?
Answer :
In Node.Js, there are 4 sorts of streams.
Readable - Stream that's used for read operation.
Writable - Stream which is used for write operation.
Duplex - Stream which may be used for both read and write operation.
Transform - A kind of duplex movement where the output is computed based on input.
Question 31. Name Some Of The Events Fired By Streams.
Answer :
Each sort of Stream is an EventEmitter example and throws several occasions at one-of-a-kind instance of times. For example, some of the usually used events are:
statistics - This occasion is fired when there may be records is to be had to study.
Quit - This occasion is fired whilst there is no extra records to examine.
Errors - This occasion is fired whilst there is any errors receiving or writing data.
End - This event is fired while all information has been flushed to underlying device
MongoDB Tutorial
Question 32. What Is Chaining In Node?
Answer :
Chanining is a mechanism to attach output of 1 flow to any other flow and create a chain of multiple stream operations. It is generally used with piping operations.
Nginx Interview Questions
Question 33. How Will You Open A File Using Node?
Answer :
Following is the syntax of the method to open a record in asynchronous mode:
fs.Open(path, flags[, mode], callback)
Parameters
Here is the outline of the parameters used:
path - This is string having record call which includes path.
Flags - Flag tells the conduct of the file to be opened. All feasible values had been noted beneath.
Mode - This units the file mode (permission and sticky bits), but best if the document changed into created. It defaults to 0666, readable and writeable.
Callback - This is the callback characteristic which receives arguments (err, fd).
Angular JS Interview Questions
Question 34. How Will You Read A File Using Node?
Answer :
Following is the syntax of one of the methods to examine from a file:
fs.Study(fd, buffer, offset, duration, position, callback)
This approach will use record descriptor to read the report, if you want to examine file the use of document name without delay then you definately should use another approach to be had.
Parameters
Here is the description of the parameters used:
fd - This is the report descriptor again with the aid of report fs.Open() method.
Buffer - This is the buffer that the records will be written to.
Offset - This is the offset in the buffer to begin writing at.
Length - This is an integer specifying the number of bytes to read.
Function - This is an integer specifying where to begin studying from within the document. If role is null, information may be examine from the current document role.
Callback - This is the callback function which gets the three arguments, (err, bytesRead, buffer).
Question 35. How Will You Write A File Using Node?
Answer :
Following is the syntax of one of the methods to jot down right into a record:
fs.WriteFile(filename, records[, options], callback)
This technique will over-write the file if document already exists. If you want to jot down into an current record you then must use every other method to be had.
Parameters
Here is the outline of the parameters used:
course - This is string having document name along with route.
Facts - This is the String or Buffer to be written into the document.
Options - The 0.33 parameter is an item so that it will hold encoding, mode, flag. By default encoding is utf8, mode is octal cost 0666 and flag is 'w'
callback - This is the callback function which gets a single parameter err and used to to go back errors in case of any writing error.
Question 36. How Will You Close A File Using Node?
Answer :
Following is the syntax of one of the methods to shut an opened report:
fs.Near(fd, callback)
Parameters
Here is the description of the parameters used:
fd - This is the report descriptor again via report fs.Open() technique.
Callback - This is the callback feature which receives no arguments apart from a possible exception are given to the finishing touch callback.
Ruby Interview Questions
Question 37. How Will You Get Information About A File Using Node?
Answer :
Following is the syntax of the technique to get the records approximately a record:
fs.Stat(path, callback)
Parameters
Here is the description of the parameters used:
route - This is string having record name which includes course.
Callback - This is the callback characteristic which receives two arguments (err, stats) wherein stats is an item of fs.Stats type which is outlined underneath in the instance.
Question 38. How Will You Truncate A File Using Node?
Answer :
Following is the syntax of the method to truncate an opened file:
fs.Ftruncate(fd, len, callback)
Parameters
Here is the description of the parameters used:
fd - This is the document descriptor back by document fs.Open() technique.
Len - This is the duration of the file and then document might be truncated.
Callback - This is the callback function which receives no arguments other than a likely exception are given to the of entirety callback.
Question 39. How Will You Delete A File Using Node?
Answer :
Following is the syntax of the technique to delete a report:
fs.Unlink(route, callback)
Parameters
Here is the outline of the parameters used:
direction - This is the document name along with route.
Callback - This is the callback function which receives no arguments other than a possible exception are given to the finishing touch callback.
Question forty. How Will You Create A Directory?
Answer :
Following is the syntax of the approach to create a listing:
fs.Mkdir(course[, mode], callback)
Parameters
Here is the description of the parameters used:
path - This is the directory call inclusive of direction.
Mode - This is the listing permission to be set. Defaults to 0777.
Callback - This is the callback function which receives no arguments apart from a likely exception are given to the final touch callback.
Ext JS Interview Questions
Question 41. How Will You Delete A Directory?
Answer :
Following is the syntax of the technique to take away a listing:
fs.Rmdir(direction, callback)
Parameters
Here is the description of the parameters used:
course - This is the listing call along with path.
Callback - This is the callback function which receives no arguments aside from a probable exception are given to the of entirety callback.
Question forty two. How Will You Read A Directory?
Answer :
Following is the syntax of the method to study a listing:
fs.Readdir(course, callback)
Parameters
Here is the description of the parameters used:
direction - This is the directory call such as route.
Callback - This is the callback characteristic which gets two arguments (err, files) in which documents is an array of the names of the documents within the listing except for '.' and '..'.
Java Abstraction Interview Questions
Question forty three. What Is The Purpose Of __filename Variable?
Answer :
The __filename represents the filename of the code being done. This is the resolved absolute path of this code file. For a main software this isn't always the equal filename used in the command line. The price interior a module is the direction to that module report.
Question 44. What Is The Purpose Of __dirname Variable?
Answer :
The __dirname represents the name of the listing that the presently executing script is living in.
Question forty five. What Is The Purpose Of Settimeout Function?
Answer :
The setTimeout(cb, ms) global characteristic is used to run callback cb after at least ms milliseconds. The real delay depends on outside factors like OS timer granularity and gadget load. A timer cannot span extra than 24.8 days.
This feature returns an opaque price that represents the timer which can be used to clean the timer.
Question forty six. What Is The Purpose Of Cleartimeout Function?
Answer :
The clearTimeout( t ) global function is used to forestall a timer that became formerly created with setTimeout(). Here t is the timer back through setTimeout() characteristic.
Question 47. What Is The Purpose Of Setinterval Function?
Answer :
The setInterval(cb, ms) worldwide feature is used to run callback cb again and again after at the least ms milliseconds. The actual postpone relies upon on external factors like OS timer granularity and gadget load. A timer cannot span more than 24.Eight days.
This feature returns an opaque cost that represents the timer which may be used to clear the timer the use of the function clearInterval(t).
Question 48. What Is The Purpose Of Console Object?
Answer :
console item is used to Used to print data on stdout and stderr.
Question forty nine. What Is The Purpose Of Process Object?
Answer :
manner object is used to get statistics on modern process. Provides a couple of activities associated with technique activities.
Question 50. Why To Use Node.Js?
Answer :
It is used to increase I/O in depth net packages like video streaming sites, unmarried page programs (SPA) and different internet applications. Node.Js is open source and used by heaps of builders around the sector.
