80+ Node JS Interview Questions And Answers 2020

Spread the love

Table of Contents

Node JS Interview Questions For Fresher & Experienced 2020

What is Node.js?

Node.js is a really highly effective JavaScript based mostly platform or framework which is constructed on Google Chrome’s JavaScript V8 Engine.

 Why to make use of Node.js?

It is used to develop I/O intensive internet purposes like video streaming websites, single web page purposes (SPA) and different internet purposes. Node.js is open supply and utilized by hundreds of builders all over the world.

Who developed Node.js?

Node.js was developed in 2009 by Ryan Dahl.

What are the options of Node.js?

Below are the options of Node.js:

  • Very Fast
  • Event pushed and Asynchronous
  • Single Threaded however extremely Scalable

Explain REPL in Node.js?

REPL stands for Read Eval Print Loop. Node.js comes with bundled REPL atmosphere which performs the next desired duties

  • Eval
  • Print
  • Loop
  • Read

Explain variables in Node.js?

Variables are used to retailer values and print later like all typical scripts. If “var” key phrase is used then worth is saved in variable. You can print the worth within the variable utilizing – console.log().

Eg:
$ node
> a = 30
30
> var b = 50
undefined
> a + b
80
> console.log(“Hi”)
Hi
undefined

Node JS Interview Questions

What is the newest model of Node.js out there?

Latest model of Node.js is – v0.10.36.

List out some REPL instructions in Node.js?

Below are the record of REPL instructions:

  • Ctrl + c – For terminating the present command.
  • Ctrl + c twice – For terminating REPL.
  • Ctrl + d – For terminating REPL.
  • Tab Keys – record of all the present instructions.
  • .break – exit from multiline expression.
  • .save with filename – save REPL session to a file.

Mention the command to cease REPL in Node.js?

Command – ctrl + c twice is used to cease REPL.

Explain NPM in Node.js?

NPM stands for Node Package Manager (npm) and there are two functionalities which NPM takes care of primarily and they’re:

  • Online repositories for node.js modules or packages, which may be searched on search.nodejs.org
  • Dependency Management, Version Management and command line utility for putting in Node.js packages.

Mention command to confirm the NPM model in Node.js?

Below command can be utilized to confirm the NPM model:

$ npm –version

How you’ll be able to replace NPM to new model in Node.js?

Below instructions can be utilized for updating NPM to new model:

$ sudo npm set up npm -g
/usr/bin/npm -> /usr/lib/node_modules/npm/bin/npm-cli.js
[email protected] /usr/lib/node_modules/npm

Explain callback in Node.js?

Callback is named as soon as the asynchronous operation has been accomplished. Node.js closely makes use of callbacks and all API’s of Node.js are written to help callbacks.

Node JS Interview Questions And Answers

How Node.js may be made extra scalable?

Node.js works good for I/O sure and never CPU sure work. For occasion if there’s a operate to learn a file, file studying might be began throughout that instruction after which it strikes onto subsequent instruction and as soon as the I/O is finished or accomplished it’ll name the callback operate. So there won’t be any blocking.

Explain international set up of dependencies?

Globally put in dependencies or packages are saved in <user-directory>/npm listing and these dependencies can be utilized in Command Line Interface operate of any node.js.

Explain native set up of dependencies?

By default npm will set up the dependency within the native mode. Here native mode refers back to the bundle set up in node_modules listing mendacity within the folder the place Node software is current. “require ()” is used to entry the regionally deployed packages.

Explain Package.JSON?

This might be current within the root listing of any Node module/software and might be used to outline the properties of a bundle.

Explain “Callback hell”?

“Callback hell” might be referred to closely nested callbacks which has turn out to be unreadable or unwieldly.

What are “Streams” in Node.JS?

“Streams” are objects which is able to allow you to learn the info from supply and write knowledge to vacation spot as a steady course of.

Node JS Interview Questions And Answer

What you imply by chaining in Node.JS?

It’s a mechanism by which output of 1 stream might be related to a different stream and thus creating a sequence of a number of stream operations.

Explain Child course of module?

Child course of module has following three main methods to create youngster processes –

spawn – child_process.spawn launches a brand new course of with a given command.
exec – child_process.exec methodology runs a command in a shell/console and buffers the output.
fork – The child_process.fork methodology is a particular case of the spawn() to create youngster processes.

Why to make use of exec methodology for Child course of module?

“exec” methodology runs a command in a shell and buffers the output. Below is the command –

child_process.exec(command[, options], callback)

List out the parameters handed for Child course of module?

Below are the record of parameters handed for Child Process Module:

child_process.exec(command[, options], callback)
command – This is the command to run with space-separated arguments.
choices – This is an object array which contains a number of following choices –

  • cwd
  • uid
  • gid
  • killSignal
  • maxBuffer
  • encoding
  • env
  • shell
  • timeout

callback – This is the operate which is will get 2 arguments – stdout, stderr and error.

Node JS Interview Questions For Experienced

What is using methodology – “spawn()”?

This methodology is used to launch a brand new course of with the given instructions. Below is the tactic signature –

child_process.spawn(command[, args][, options])

What is using methodology – “fork()”?

This methodology is a particular case for method- “spawn()” for creating node processes. The methodology signature –

child_process.fork(modulePath[, args][, options])

Explain Piping Stream?

This is a mechanism of connecting one stream to different and that is principally used for getting the info from one stream and move the output of this to different stream.

What can be the restrict for Piping Stream?

There won’t be any restrict for piping stream.

Explain FS module ?

Here FS stands for “File System” and fs module is used for File I/O. FS module may be imported within the following manner –

var check = require(“fs”)

Explain “Console” in Node.JS?

“Console” is a worldwide object and might be used for printing to stderr and stdout and this might be utilized in synchronous method in case of vacation spot is both file or terminal or else it’s utilized in asynchronous method when it’s a pipe.

Node JS Interview Questions And Answers For Experienced

Explain – “console.log([data][, …])” assertion in Node.JS?

This assertion is used for printing to “stdout” with newline and this operate takes a number of arguments as “printf()”.

What you imply by “process”?

“process” is a worldwide object and might be used to symbolize a node course of.

Explain exit codes in Node.JS? List out some exit codes?

Exit code might be used when the method must be ended with specified code. Below are the record of exit codes in Node.JS –

  • Fatal Error
  • Non-function Internal Exception Handler
  • Internal JavaScript Parse Error
  • Uncaught Fatal Exception
  • Unused
  • Internal JavaScript Evaluation Failure
  • Internal Exception Handler Run-Time Failure

List out the properties of course of?

Below are the helpful properties of course of:

  • Platform
  • Stdin
  • Stdout
  • Stderr
  • execPath
  • predominantModule
  • execArgv
  • config
  • arch
  • title
  • model
  • argv
  • env
  • exitCode

Define OS module?

OS module is used for some fundamental working system associated utility features. Below is the syntax for importing OS module:

var MyopSystem = require(“os”)

What is the property of OS module?

os.EOL – Constant for outlining applicable finish of line marker for OS.

Explain “Path” module in Node.JS?

“Path” module might be used for remodeling and dealing with file paths. Below is the syntax of path module –

var mypath = require(“path”)

Node JS Interview Questions For Fresher

Explain “Net” module in Node.JS?

“Net” module is getting used for creating each purchasers and servers. It will present asynchronous community wrapper. Below is the syntax of Net module –

var mynet = require(“net”)

List out the variations between AngularJS and NodeJS?

AngularJS is an online software improvement framework. It’s a JavaScript and it’s totally different from different internet app frameworks written in JavaScript like jQuery. NodeJS is a runtime atmosphere used for constructing server-side purposes whereas AngularJS is a JavaScript framework primarily helpful in constructing/creating client-side a part of purposes which run inside an online browser.

NodeJS is consumer facet server facet language?

NodeJS is a runtime system, which is used for creating server-side purposes.

What are the benefits of NodeJS?

Below are the record of benefits of NodeJS:

Javascript: It’s a javascript which can be utilized on frontend and backend.
Community Driven: NodeJS has nice open supply group which has developed many wonderful modules for NodeJS so as to add further capabilities to NodeJS purposes.

In which eventualities NodeJS works properly?

NodeJS is just not applicable to make use of in eventualities the place single-threaded calculations are going to be the holdup.

What you imply by JSON?

JavaScript Object Notation (JSON) is a sensible, compound, broadly fashionable knowledge trade format. This will allow JavaScript builders to shortly assemble APIs.

Node JS Advanced Interview Questions

Explain “Stub”?

Stub is a small program, which substitutes for an extended program, presumably to be loaded later and that’s positioned remotely. Stubs are features/applications that simulate the behaviors of elements/modules.

List out all Node.JS variations out there?

Below are the record of all NodsJS variations supported in working methods:

  • WorkingSystem Node.js model
  • Windows node-v0.12.0-x64.msi
  • Linux node-v0.12.0-linux-x86.tar.gz
  • Mac node-v0.12.0-darwin-x86.tar.gz
  • SunOS node-v0.12.0-sunos-x86.tar.gz

Explain “Buffer class” in Node.JS?

It is a worldwide class which may be accessed in an software with out importing buffer modules.

How we are able to convert Buffer to JSON?

The syntax to transform Buffer to JSON is as proven below

buffer.toJSON()

How to concatenate buffers in NodeJS?

The syntax to concatenate buffers in NodeJS is:
var MyConctBuffer = Buffer.concat([myBuffer1, myBuffer2]);

How to check buffers in NodeJS?

To examine buffers in NodeJS, use following code –
Mybuffer1.examine(Mybuffer2);

How to repeat buffers in NodeJS?

Below is the syntax to repeat buffers in NodeJS:
buffer.copy(goalBuffer[, targetStart][, sourceStart][, sourceEnd])

Interview Questions Node JS

What are the variations between “readUIntBE” and “writeIntBE” in Node.JS?

readUIntBE – It’s a generalized model of all numeric learn strategies, which helps as much as 48 bits accuracy. Setting noAssert to “true” to skip the validation.
writeIntBE – This will write the worth to the buffer on the specified byteLength and offset and it helps upto 48 bits of accuracy.

Why to make use of “__filename” in Node.JS?

“__filename” is used to symbolize the filename of the code which is being executed. It used to resolve absolutely the path of file. Below is the pattern code for a similar –

Console.log(__filename);

Why to make use of “SetTimeout” in Node.JS?

This is the worldwide operate and it’s used to run the callback after some milliseconds.

Syntax of this methodology:

setTimeout(callbackmethod, millisecs)

Why to make use of “ClearTimeout” in Node.JS?

This is the worldwide operate and it’s used to cease a timer which was created throughout “settimeout()”.

Explain Web Server?

It is a software program app which is able to deal with the HTTP requests by consumer (eg: browser) and can return internet pages to consumer as a response. Most of internet server helps – server facet scripts utilizing scripting languages. Example of internet server is Apache, which is generally used webserver.

Advanced Node JS Interview Questions

List out the layers concerned in Web App Architechure?

Below are the layers utilized in Web Apps:

  • Client – Which makes HTTP request to the server. Eg: Browsers.
  • Server – This layer is used to intercept the requests from consumer.
  • Business – It could have software server utilized by internet servers for processing.
  • Data – This layer could have databases primarily or any supply of knowledge.

Explain “Event Emitter” in Node.JS?

It is part of Events module. When occasion of EventEmitter faces any error, it’ll emit an ‘error’ occasion. “Event Emitters” offers a number of properties like – “emit” and “on”.

“on” property is used for binding the operate with occasion.
“emit” property is used for firing an occasion.

Explain “NewListener” in Node.JS?

This occasion is being emitted each time any listener is added. So when occasion is triggered the listener might not have been faraway from listener array for the occasion.

Why to make use of Net.socket in Node.JS?

This object is an abstraction of a neighborhood socket or TCP. web.Socket situations implement a duplex Stream interface. These may be created by the person and used as a consumer (with join() operate) or they are often created by Node and may be handed to the person by the ‘connection’ occasion of a server.

Node JS Basic Interview Questions

Which occasions are emitted by Net.socket?

Below are the record of occasions emitted by Net.socket:

  • Connect
  • Lookup
  • End
  • Data
  • Close
  • Drain
  • Timeout
  • Error

Explain “DNS module” in Node.JS?

This module is used for DNS lookup and to make use of underlying OS title decision. This used to offer asynchronous community wrapper. DNS module may be imported like –

var mydns = require(“dns”)

Explain binding in area module in Node.JS?

Below are the bindings in area modules:

  • External Binding
  • Internal Binding

Explain RESTful Web Service?

Web companies which makes use of REST structure might be often known as RESTful Web Services. These internet companies makes use of HTTP protocol and HTTP strategies.

How to truncate the file in Node.JS?

Below command can be utilized for truncating the file:

fs.ftruncate(fd, len, callback)


Spread the love