SlideShare a Scribd company logo
TechieVarsity - Node.js Interview Questions
Page 1 of 10
1
1. Why use Node.js?
Node.js makes building scalable network programs easy. Some of its advantages include:
 It offers a unified programming language and data type
 Everything is asynchronous
 It yields great concurrency
 It is generally fast
 It almost never blocks
2. 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 can be achieved as
opposed to the typical thread-based implementation.
3. What are the functionalities of NPM in Node.js?
NPM (Node package Manager) provides two functionalities:
 Command line utility for installing packages, version management and dependency
management of Node.js packages
 Online repository for Node.js packages
4. What is the difference between Node.js and Ajax?
 Ajax is primarily designed for dynamically updating a particular section of a page’s
content, without having to update the entire page.
 Node.js is used for developing client-server applications.
 Node.js and Ajax (Asynchronous JavaScript and XML) are the advanced
implementation of JavaScript. They all serve completely different purposes.
5. What are “streams” in Node.js? Explain the different types of streams present
in Node.js.
Streams are objects that allow reading of data from the source and writing of data to
the destination as a continuous process.
There are four types of streams.
 to facilitate both read and write operations
 is a form of Duplex stream that performs computations based on the available input
 to facilitate the reading operation
 to facilitate the writing operation
6. What are exit codes in Node.js? List some exit codes.
Exit codes are specific codes that are used to end a “process” (a global object used to
represent a node process).
TechieVarsity - Node.js Interview Questions
Page 2 of 10
2
Examples of exit codes include:
 Internal Exception handler Run-Time Failure
 Internal JavaScript Evaluation Failure
 Unused
 Uncaught Fatal Exception
 Fatal Error
 Non-function Internal Exception Handler
7. What are Globals in Node.js?
Three keywords in Node.js constitute as Globals. These are:
 Buffer – it is a class in Node.js to handle binary data.
 Global – it represents the Global namespace object and acts as a container for all
other objects.
 Process – It is one of the global objects but can turn a synchronous function into an
async callback. It can be accessed from anywhere in the code and it primarily gives
back information about the application or the environment.
8. How can you avoid callback hells?
There are lots of ways to solve the issue of callback hells:
 modularization: break callbacks into independent functions
 use a control flow library, like async
 use generators with Promises
 use async/await
9. What's wrong with the code snippet?
new promise((resolve,reject) => {
throw new Error(‘error’)
then(console.log)
The Solution
As there is no catch after then. This way the error will be a silent one; there will be no
indication of an error thrown. To fix it, you can do the following:
new promise((resolve,reject) => {
throw new Error(‘error’)
then(console.log).catch(console.error)
TechieVarsity - Node.js Interview Questions
Page 3 of 10
3
10. What's output of the following code snippet?
Answer: 2
11. Explain flow of the above code snippet
 A new Promise is created, that will resolve to 1.
 The resolved value is incremented with 1 (so it is 2 now), and returned instantly.
 The resolved value is discarded, and an error is thrown.
 The error is discarded, and a new value (1) is returned.
 The execution did not stop after the catch, but before the exception was handled, it
continued, and a new, incremented value (2) is returned.
 The value is printed to the standard output.
 This line won't run, as there was no exception.
12. What are perfect areas to use Node.js?
 JSON APIs based Applications
 Single Page Applications
 I/O bound Applications
 Data Streaming Applications
 Data Intensive Real-time Applications (DIRT)
13. What Are The Key Features Of Node.Js?
 There is an Active and vibrant community for the Node.js framework
 No Buffering
 Asynchronous event driven IO helps concurrent request handling
 Fast in Code execution
 Single Threaded but Highly Scalable
 Node.js library uses JavaScript
Promise.resolve(1)
.then((x) => x +1)
.then((x) => { throw new Error(‘My Error’) })
.catch(() => 1)
.then ((x) => x +1 )
. then ((x) => console.log(x))
. catch(console.error)
TechieVarsity - Node.js Interview Questions
Page 4 of 10
4
14. When To Not Use Node.Js?
We should not use it for cases where the application requires long processing time. If the
server is doing some calculation, it won’t be able to process any other requests. Hence,
Node.js is best when processing needs less dedicated CPU time.
15. List of most commonly used IDEs for developing node.js applications.
 Cloud9.
 JetBrains WebStorm.
 JetBrains InteliJ IDEA.
 Komodo IDE.
 Eclipse.
 Atom.
16. How to Get Post Data in Node.Js?
17. How to Make Post Request in Node.Js?
18. How to create Http server In Node.Js?
app.use(express.bodyParser());
app.post(‘/’,function(request,response){
console.log(request.body.user);
});
Var request = require(‘request’);
Request. Post(
‘http://www.example.com/action’,
{ form: {key: ‘value’}},
Function (error, response, body) {
If (!error && response.statusCode == 200) {
console.log(body)
}
}
var http = require(‘http’);
var requestListener = function(request,response) {
TechieVarsity - Node.js Interview Questions
Page 5 of 10
5
19. What Is The Difference Between Nodejs, AJAX, And JQuery?
Node.Js
It is a server-side platform for developing client-server applications.
AJAX (Asynchronous Javascript and XML)
It is a client-side scripting technique, primarily designed for rendering the contents of a
page without refreshing it.
JQuery
It is a famous JavaScript module with complements AJAX, DOM traversal, looping and so on.
This library provides many useful functions to help in JavaScript development.
20. How many types of Streams are present in Node.js?
 <Readable> – This is the Stream to be used for reading operation.
 <Writable> – It facilitates the write operation.
 <Duplex> – This Stream can be used for both the read and write operations.
 <Transform> – It is a form of a duplex Stream, which performs the computations based on
the available input.
21. What Is Package.Json?
 It is a plain JSON (JavaScript Object Notation) text file which contains all metadata
information about Node.js Project or application.
 NPM (Node Package Manager) uses <package.json> file. It includes details of the Node.js
application or package. This file contains a no. of different directives or elements. These
directives guide NPM, about how to handle a module or package.
response.writeHead(200, {‘Content-Type’:’text/plain’});
response.end(‘Welcome’);
}
Var server = http.createServer(requestListener);
server.listen(8080);
TechieVarsity - Node.js Interview Questions
Page 6 of 10
6
22. Name some of the attributes of package.json?
Following are the attributes of Package.json
name– name of the package
version– version of the package
description– description of the package
homepage– homepage of the package
author– author of the package
contributors– name of the contributors to the package
dependencies– list of dependencies. npm automatically installs all the dependencies mentioned
here in the node_module folder of the package.
brepository– repository type and url of the package
main– entry point of the package
keywords– keywords
23. File IO operations
Open a file using Node
fs.open(path, flags[, mode], callback)
Parameters
Here is the description of the parameters used:
1. path– This is string having file name including path.
2. flags– Flag tell the behavior of the file to be opened. All possible values have been mentioned
below.
3. mode– This sets the file mode (permission and sticky bits), but only if the file was created. It
defaults to 0666, readable and writeable.
4. callback– This is the callback function which gets two arguments (err, fd).
Read a file using Node
fs.read(fd, buffer, offset, length, position, callback)
This method will use file descriptor to read the file, if you want to read file using file name directly then you
should use another method available.
Parameters
Here is the description of the parameters used:
1. fd– This is the file descriptor returned by file fs.open() method.
2. buffer– This is the buffer that the data will be written to.
3. offset– This is the offset in the buffer to start writing at.
4. length– This is an integer specifying the number of bytes to read.
5. position– This is an integer specifying where to begin reading from in the file. If position is null, data will be
read from the current file position.
6. callback– This is the callback function which gets the three arguments, (err, bytesRead, buffer).
TechieVarsity - Node.js Interview Questions
Page 7 of 10
7
Write a file using Node
fs.writeFile(filename, data[, options], callback)
This method will over-write the file if file already exists. If you want to write into an existing file then you
should use another method available.
Parameters
Here is the description of the parameters used:
1. path– This is string having file name including path.
2. data– This is the String or Buffer to be written into the file.
3. options– The third parameter is an object which will hold {encoding, mode, flag}. By default encoding is
utf8, mode is octal value 0666 and flag is ‘w’
4. callback– This is the callback function which gets a single parameter err and used to return error in case of
any writing error.
How will you close a file using Node?
Following is the syntax of one of the methods to close an opened file:
fs.close(fd, callback)
Parameters
Here is the description of the parameters used:
1. fd– This is the file descriptor returned by file fs.open() method.
2. callback– This is the callback function which gets no arguments other than a possible exception are given to
the completion callback.
How will you delete a file using Node?
Following is the syntax of the method to delete a file:
fs.unlink(path, callback)
Parameters
Here is the description of the parameters used:
1. path– This is the file name including path.
2. callback– This is the callback function which gets no arguments other than a possible exception are given to
the completion callback.
24. How to handle the “Unhandled exceptions” in Node.js?
It can be caught at the "Process level" by attaching a handler for uncaughtException event.
Example:
Process.on (‘uncaught Exception’, function (err) {
Console.log(‘Caught exception: ‘ + err);
});
25. How to build a “Hello World” Application in Node.js?
 Create a folder called ‘hello_world’.
TechieVarsity - Node.js Interview Questions
Page 8 of 10
8
 Initialize the project with command ‘npm init’, this will create the package.json.
 The project name only support URL friendly character and no longer support Capital
letters.
 This command will create the package.json.
A. Install all dependencies using the command ‘npm install’.
B. Start the project by running the command ‘node’.
C. This will provide the option to write other things.
D. Let’s print ‘Hello World!’.
E. Every JavaScript function must return something, this console.log return undefined ,
therefore , the second line prints ‘undefined’.
F. Create a file called ‘index.js’ inside ‘hello_world’ folder.
From command line tool run ‘node index.js’.
26. Where to deploy node application?
 Node.js app cannot be deployed on existing hosts like shared web hosting etc.
 Use VPS or dedicated servers to install node and run your application.
 The easiest way to deploy node application is to use a scalable service like Heroku, which
is completely free and you only need to pay when you are using more resources.
27. Explain Node.js Code Execution Process?
The steps of code execution are given below:
 Clients send theirs request to Node.js Server.
 Node.js Server receives those requests and places them into a processing Queue that is
known as “Event Queue”.
 Node.js uses JavaScript Event Loop to process each client request. This Event loop is an
indefinite loop to receive requests and process them. Event Loop continuously checks for
client’s requests placed in Event Queue. If requests are available, then it process them
one by one.
 If the client request does not require any blocking IO operations, then it process
everything, prepare the response and send it back to the client.
 If the client request requires some blocking IO operations like interacting with database,
file system, external services then it uses C++ thread pool to process these operations.
28. What are core modules in Node.js?
Assert It is used by Node.js for testing itself. Usage - require('assert').
Buffer It is used to perform operations on raw bytes of data which reside in
memory. Usage - require('buffer').
Child Process It is used by node.js for managing child processes. It can be accessed with It
Usage - require('child_process').
Cluster This module is used by Node.js to take advantage of multi-core systems, so
that it can handle more load. Usage -require('cluster').
TechieVarsity - Node.js Interview Questions
Page 9 of 10
9
Console It is used to write data to console. Node.js has a Console object which
contains functions to write data to console. Usage -require('console').
Crypto It is used to support cryptography for encryption and decryption. Usage -
require('crypto').
Debugger It is used for code debugging. To use this, start Node.js with the debug
argument and for debugging add debugger; statement in your code.
DNS It is used to perform operations like lookup and resolve on domain names.
Usage - require('dns').
Events It is used for events handling in node.js. In node.js, events are emitted by
other node objects. Usage - require('events').
File System It is used to perform operations on files. Usage - require('fs').
HTTP It is used to create Http server and Http client. Usage - require('http').
Net It used to create TCP server and client which can communicate over a
network using TCP protocol. Usage - require('net').
OS It is used to provide basic operating system related utility functions. Usage -
require('os').
Path It is used to perform operations on paths of files. Usage - require('path').
Process It is a global object and provides information related to the program
execution. Usage - require() method.
Query String It is used to deal with query strings.
Stream It is used to stream data between two entities. Usage - require('stream').
Timers All of the timer functions are global and deals with time. Usage - require()
method.
Url It is used for URL resolution and parsing. Usage - require('url').
Util It is primarily designed to support the needs of Node.js internal APIs. It is
also useful for debugging. Usage - require('util').
29. What are various error handling patterns in Node.js?
There are following basic patterns you can use for errors handling in Node.js:
• Try/Catch - The most commonly used way to handle errors in any programming language
is try/catch blocks. Also, try/catch block executes in synchronous fashion; hence suitable
for compiled languages like C#, Java etc.
try {
throw new Error('throw error');
} catch (e) {
console.log(e);
}
Node.js to handle errors for synchronous code.
• Callback – This way is used to handle errors in any callback without using nested try
catch statements. In this way you have to pass a callback, function(err, result) which will
be invoked when the asynchronous operation completes. Here err parameter returns the
error and result is the result of completed operations, depending on whether the
operation succeeded or failed.
//request in express
TechieVarsity - Node.js Interview Questions
Page 10 of 10
10
app.get('/', function (req, res) {
db.query('sql_query', function (err, result) {
if (err) {
res.writeHead(500);
res.end();
console.log(err);
}
else {
res.send(result);
}
});
});
30. What are various node.js web development frameworks?
The best and most powerful node.js web development frameworks to build real time and
scalable web applications with ease are given below:
MVC frameworks
• Express
• Koa
• Hapi
• Sails
• Nodal
31. What are various node.js testing frameworks?
The most popular node.js testing libraries and frameworks are given below:
• Node.js assert
• Mocha
• Chai.js
• Should.js
• Nodeunit
• Vows.js
• Jasmine

More Related Content

What's hot

An overview of selenium webdriver
An overview of selenium webdriverAn overview of selenium webdriver
An overview of selenium webdriverAnuraj S.L
 
자바에서 null을 안전하게 다루는 방법
자바에서 null을 안전하게 다루는 방법자바에서 null을 안전하게 다루는 방법
자바에서 null을 안전하게 다루는 방법Sungchul Park
 
Node.js Tutorial for Beginners | Node.js Web Application Tutorial | Node.js T...
Node.js Tutorial for Beginners | Node.js Web Application Tutorial | Node.js T...Node.js Tutorial for Beginners | Node.js Web Application Tutorial | Node.js T...
Node.js Tutorial for Beginners | Node.js Web Application Tutorial | Node.js T...Edureka!
 
NodeJS guide for beginners
NodeJS guide for beginnersNodeJS guide for beginners
NodeJS guide for beginnersEnoch Joshua
 
Enterprise java unit-1_chapter-2
Enterprise java unit-1_chapter-2Enterprise java unit-1_chapter-2
Enterprise java unit-1_chapter-2sandeep54552
 
Enterprise java unit-1_chapter-1
Enterprise java unit-1_chapter-1Enterprise java unit-1_chapter-1
Enterprise java unit-1_chapter-1sandeep54552
 
Enterprise java unit-1_chapter-3
Enterprise java unit-1_chapter-3Enterprise java unit-1_chapter-3
Enterprise java unit-1_chapter-3sandeep54552
 
Introduction Of Software Engineering.pptx
Introduction Of Software Engineering.pptxIntroduction Of Software Engineering.pptx
Introduction Of Software Engineering.pptxAnimeshMani4
 
SSR with React - Connecting Next.js with WordPress
SSR with React - Connecting Next.js with WordPressSSR with React - Connecting Next.js with WordPress
SSR with React - Connecting Next.js with WordPressImran Sayed
 
Modern UI Development With Node.js
Modern UI Development With Node.jsModern UI Development With Node.js
Modern UI Development With Node.jsRyan Anklam
 
IDC 서버 몽땅 AWS로 이전하기 위한 5가지 방법 - 윤석찬 (AWS 테크에반젤리스트)
IDC 서버 몽땅 AWS로 이전하기 위한 5가지 방법 - 윤석찬 (AWS 테크에반젤리스트) IDC 서버 몽땅 AWS로 이전하기 위한 5가지 방법 - 윤석찬 (AWS 테크에반젤리스트)
IDC 서버 몽땅 AWS로 이전하기 위한 5가지 방법 - 윤석찬 (AWS 테크에반젤리스트) Amazon Web Services Korea
 
Web worker in your angular application
Web worker in your angular applicationWeb worker in your angular application
Web worker in your angular applicationSuresh Patidar
 

What's hot (20)

An overview of selenium webdriver
An overview of selenium webdriverAn overview of selenium webdriver
An overview of selenium webdriver
 
Node js
Node jsNode js
Node js
 
Node.js Basics
Node.js Basics Node.js Basics
Node.js Basics
 
자바에서 null을 안전하게 다루는 방법
자바에서 null을 안전하게 다루는 방법자바에서 null을 안전하게 다루는 방법
자바에서 null을 안전하게 다루는 방법
 
Node.js Tutorial for Beginners | Node.js Web Application Tutorial | Node.js T...
Node.js Tutorial for Beginners | Node.js Web Application Tutorial | Node.js T...Node.js Tutorial for Beginners | Node.js Web Application Tutorial | Node.js T...
Node.js Tutorial for Beginners | Node.js Web Application Tutorial | Node.js T...
 
NodeJS guide for beginners
NodeJS guide for beginnersNodeJS guide for beginners
NodeJS guide for beginners
 
Express js
Express jsExpress js
Express js
 
Selenium web driver
Selenium web driverSelenium web driver
Selenium web driver
 
Enterprise java unit-1_chapter-2
Enterprise java unit-1_chapter-2Enterprise java unit-1_chapter-2
Enterprise java unit-1_chapter-2
 
Node js crash course session 1
Node js crash course   session 1Node js crash course   session 1
Node js crash course session 1
 
Enterprise java unit-1_chapter-1
Enterprise java unit-1_chapter-1Enterprise java unit-1_chapter-1
Enterprise java unit-1_chapter-1
 
Enterprise java unit-1_chapter-3
Enterprise java unit-1_chapter-3Enterprise java unit-1_chapter-3
Enterprise java unit-1_chapter-3
 
Introduction Of Software Engineering.pptx
Introduction Of Software Engineering.pptxIntroduction Of Software Engineering.pptx
Introduction Of Software Engineering.pptx
 
Introduction to TDD and BDD
Introduction to TDD and BDDIntroduction to TDD and BDD
Introduction to TDD and BDD
 
Introduction to MERN
Introduction to MERNIntroduction to MERN
Introduction to MERN
 
SSR with React - Connecting Next.js with WordPress
SSR with React - Connecting Next.js with WordPressSSR with React - Connecting Next.js with WordPress
SSR with React - Connecting Next.js with WordPress
 
Modern UI Development With Node.js
Modern UI Development With Node.jsModern UI Development With Node.js
Modern UI Development With Node.js
 
IDC 서버 몽땅 AWS로 이전하기 위한 5가지 방법 - 윤석찬 (AWS 테크에반젤리스트)
IDC 서버 몽땅 AWS로 이전하기 위한 5가지 방법 - 윤석찬 (AWS 테크에반젤리스트) IDC 서버 몽땅 AWS로 이전하기 위한 5가지 방법 - 윤석찬 (AWS 테크에반젤리스트)
IDC 서버 몽땅 AWS로 이전하기 위한 5가지 방법 - 윤석찬 (AWS 테크에반젤리스트)
 
Cypress Automation
Cypress  AutomationCypress  Automation
Cypress Automation
 
Web worker in your angular application
Web worker in your angular applicationWeb worker in your angular application
Web worker in your angular application
 

Similar to Top 30 Node.js interview questions

Introduction to Node.js
Introduction to Node.jsIntroduction to Node.js
Introduction to Node.jsVikash Singh
 
High Performance NodeJS
High Performance NodeJSHigh Performance NodeJS
High Performance NodeJSDicoding
 
Nt1310 Unit 3 Language Analysis
Nt1310 Unit 3 Language AnalysisNt1310 Unit 3 Language Analysis
Nt1310 Unit 3 Language AnalysisNicole Gomez
 
Beginning MEAN Stack
Beginning MEAN StackBeginning MEAN Stack
Beginning MEAN StackRob Davarnia
 
Node.js: A Guided Tour
Node.js: A Guided TourNode.js: A Guided Tour
Node.js: A Guided Tourcacois
 
Building Applications With the MEAN Stack
Building Applications With the MEAN StackBuilding Applications With the MEAN Stack
Building Applications With the MEAN StackNir Noy
 
Node.JS Interview Questions .pdf
Node.JS Interview Questions .pdfNode.JS Interview Questions .pdf
Node.JS Interview Questions .pdfSudhanshiBakre1
 
Kalp Corporate Node JS Perfect Guide
Kalp Corporate Node JS Perfect GuideKalp Corporate Node JS Perfect Guide
Kalp Corporate Node JS Perfect GuideKalp Corporate
 
Node.js Workshop - Sela SDP 2015
Node.js Workshop  - Sela SDP 2015Node.js Workshop  - Sela SDP 2015
Node.js Workshop - Sela SDP 2015Nir Noy
 
Day in a life of a node.js developer
Day in a life of a node.js developerDay in a life of a node.js developer
Day in a life of a node.js developerEdureka!
 
Day In A Life Of A Node.js Developer
Day In A Life Of A Node.js DeveloperDay In A Life Of A Node.js Developer
Day In A Life Of A Node.js DeveloperEdureka!
 
Introduction to node.js By Ahmed Assaf
Introduction to node.js  By Ahmed AssafIntroduction to node.js  By Ahmed Assaf
Introduction to node.js By Ahmed AssafAhmed Assaf
 
Node Js Non-blocking or asynchronous Blocking or synchronous.pdf
Node Js Non-blocking or asynchronous  Blocking or synchronous.pdfNode Js Non-blocking or asynchronous  Blocking or synchronous.pdf
Node Js Non-blocking or asynchronous Blocking or synchronous.pdfDarshanaMallick
 
Introduction to Node.js
Introduction to Node.jsIntroduction to Node.js
Introduction to Node.jsWinston Hsieh
 

Similar to Top 30 Node.js interview questions (20)

node.js.pptx
node.js.pptxnode.js.pptx
node.js.pptx
 
Introduction to Node.js
Introduction to Node.jsIntroduction to Node.js
Introduction to Node.js
 
Node js beginner
Node js beginnerNode js beginner
Node js beginner
 
Introduction to Node.JS
Introduction to Node.JSIntroduction to Node.JS
Introduction to Node.JS
 
High Performance NodeJS
High Performance NodeJSHigh Performance NodeJS
High Performance NodeJS
 
Nt1310 Unit 3 Language Analysis
Nt1310 Unit 3 Language AnalysisNt1310 Unit 3 Language Analysis
Nt1310 Unit 3 Language Analysis
 
Beginning MEAN Stack
Beginning MEAN StackBeginning MEAN Stack
Beginning MEAN Stack
 
Node.js: A Guided Tour
Node.js: A Guided TourNode.js: A Guided Tour
Node.js: A Guided Tour
 
Best node js course
Best node js courseBest node js course
Best node js course
 
Building Applications With the MEAN Stack
Building Applications With the MEAN StackBuilding Applications With the MEAN Stack
Building Applications With the MEAN Stack
 
Node.JS Interview Questions .pdf
Node.JS Interview Questions .pdfNode.JS Interview Questions .pdf
Node.JS Interview Questions .pdf
 
Kalp Corporate Node JS Perfect Guide
Kalp Corporate Node JS Perfect GuideKalp Corporate Node JS Perfect Guide
Kalp Corporate Node JS Perfect Guide
 
Node.js Workshop - Sela SDP 2015
Node.js Workshop  - Sela SDP 2015Node.js Workshop  - Sela SDP 2015
Node.js Workshop - Sela SDP 2015
 
Day in a life of a node.js developer
Day in a life of a node.js developerDay in a life of a node.js developer
Day in a life of a node.js developer
 
Day In A Life Of A Node.js Developer
Day In A Life Of A Node.js DeveloperDay In A Life Of A Node.js Developer
Day In A Life Of A Node.js Developer
 
Introduction to node.js By Ahmed Assaf
Introduction to node.js  By Ahmed AssafIntroduction to node.js  By Ahmed Assaf
Introduction to node.js By Ahmed Assaf
 
Proposal
ProposalProposal
Proposal
 
Node Js Non-blocking or asynchronous Blocking or synchronous.pdf
Node Js Non-blocking or asynchronous  Blocking or synchronous.pdfNode Js Non-blocking or asynchronous  Blocking or synchronous.pdf
Node Js Non-blocking or asynchronous Blocking or synchronous.pdf
 
Introduction to Node.js
Introduction to Node.jsIntroduction to Node.js
Introduction to Node.js
 
Exploring Node.jS
Exploring Node.jSExploring Node.jS
Exploring Node.jS
 

Recently uploaded

Dominate Social Media with TubeTrivia AI’s Addictive Quiz Videos.pdf
Dominate Social Media with TubeTrivia AI’s Addictive Quiz Videos.pdfDominate Social Media with TubeTrivia AI’s Addictive Quiz Videos.pdf
Dominate Social Media with TubeTrivia AI’s Addictive Quiz Videos.pdfAMB-Review
 
Cyaniclab : Software Development Agency Portfolio.pdf
Cyaniclab : Software Development Agency Portfolio.pdfCyaniclab : Software Development Agency Portfolio.pdf
Cyaniclab : Software Development Agency Portfolio.pdfCyanic lab
 
SOCRadar Research Team: Latest Activities of IntelBroker
SOCRadar Research Team: Latest Activities of IntelBrokerSOCRadar Research Team: Latest Activities of IntelBroker
SOCRadar Research Team: Latest Activities of IntelBrokerSOCRadar
 
Abortion ^Clinic ^%[+971588192166''] Abortion Pill Al Ain (?@?) Abortion Pill...
Abortion ^Clinic ^%[+971588192166''] Abortion Pill Al Ain (?@?) Abortion Pill...Abortion ^Clinic ^%[+971588192166''] Abortion Pill Al Ain (?@?) Abortion Pill...
Abortion ^Clinic ^%[+971588192166''] Abortion Pill Al Ain (?@?) Abortion Pill...Abortion Clinic
 
Paketo Buildpacks : la meilleure façon de construire des images OCI? DevopsDa...
Paketo Buildpacks : la meilleure façon de construire des images OCI? DevopsDa...Paketo Buildpacks : la meilleure façon de construire des images OCI? DevopsDa...
Paketo Buildpacks : la meilleure façon de construire des images OCI? DevopsDa...Anthony Dahanne
 
AI/ML Infra Meetup | Reducing Prefill for LLM Serving in RAG
AI/ML Infra Meetup | Reducing Prefill for LLM Serving in RAGAI/ML Infra Meetup | Reducing Prefill for LLM Serving in RAG
AI/ML Infra Meetup | Reducing Prefill for LLM Serving in RAGAlluxio, Inc.
 
In 2015, I used to write extensions for Joomla, WordPress, phpBB3, etc and I ...
In 2015, I used to write extensions for Joomla, WordPress, phpBB3, etc and I ...In 2015, I used to write extensions for Joomla, WordPress, phpBB3, etc and I ...
In 2015, I used to write extensions for Joomla, WordPress, phpBB3, etc and I ...Juraj Vysvader
 
AI/ML Infra Meetup | ML explainability in Michelangelo
AI/ML Infra Meetup | ML explainability in MichelangeloAI/ML Infra Meetup | ML explainability in Michelangelo
AI/ML Infra Meetup | ML explainability in MichelangeloAlluxio, Inc.
 
GraphAware - Transforming policing with graph-based intelligence analysis
GraphAware - Transforming policing with graph-based intelligence analysisGraphAware - Transforming policing with graph-based intelligence analysis
GraphAware - Transforming policing with graph-based intelligence analysisNeo4j
 
Vitthal Shirke Microservices Resume Montevideo
Vitthal Shirke Microservices Resume MontevideoVitthal Shirke Microservices Resume Montevideo
Vitthal Shirke Microservices Resume MontevideoVitthal Shirke
 
Developing Distributed High-performance Computing Capabilities of an Open Sci...
Developing Distributed High-performance Computing Capabilities of an Open Sci...Developing Distributed High-performance Computing Capabilities of an Open Sci...
Developing Distributed High-performance Computing Capabilities of an Open Sci...Globus
 
BoxLang: Review our Visionary Licenses of 2024
BoxLang: Review our Visionary Licenses of 2024BoxLang: Review our Visionary Licenses of 2024
BoxLang: Review our Visionary Licenses of 2024Ortus Solutions, Corp
 
TROUBLESHOOTING 9 TYPES OF OUTOFMEMORYERROR
TROUBLESHOOTING 9 TYPES OF OUTOFMEMORYERRORTROUBLESHOOTING 9 TYPES OF OUTOFMEMORYERROR
TROUBLESHOOTING 9 TYPES OF OUTOFMEMORYERRORTier1 app
 
How to Position Your Globus Data Portal for Success Ten Good Practices
How to Position Your Globus Data Portal for Success Ten Good PracticesHow to Position Your Globus Data Portal for Success Ten Good Practices
How to Position Your Globus Data Portal for Success Ten Good PracticesGlobus
 
GlobusWorld 2024 Opening Keynote session
GlobusWorld 2024 Opening Keynote sessionGlobusWorld 2024 Opening Keynote session
GlobusWorld 2024 Opening Keynote sessionGlobus
 
A Comprehensive Appium Guide for Hybrid App Automation Testing.pdf
A Comprehensive Appium Guide for Hybrid App Automation Testing.pdfA Comprehensive Appium Guide for Hybrid App Automation Testing.pdf
A Comprehensive Appium Guide for Hybrid App Automation Testing.pdfkalichargn70th171
 
Studiovity film pre-production and screenwriting software
Studiovity film pre-production and screenwriting softwareStudiovity film pre-production and screenwriting software
Studiovity film pre-production and screenwriting softwareinfo611746
 
Field Employee Tracking System| MiTrack App| Best Employee Tracking Solution|...
Field Employee Tracking System| MiTrack App| Best Employee Tracking Solution|...Field Employee Tracking System| MiTrack App| Best Employee Tracking Solution|...
Field Employee Tracking System| MiTrack App| Best Employee Tracking Solution|...informapgpstrackings
 
WSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital Transformation
WSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital TransformationWSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital Transformation
WSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital TransformationWSO2
 

Recently uploaded (20)

Dominate Social Media with TubeTrivia AI’s Addictive Quiz Videos.pdf
Dominate Social Media with TubeTrivia AI’s Addictive Quiz Videos.pdfDominate Social Media with TubeTrivia AI’s Addictive Quiz Videos.pdf
Dominate Social Media with TubeTrivia AI’s Addictive Quiz Videos.pdf
 
Cyaniclab : Software Development Agency Portfolio.pdf
Cyaniclab : Software Development Agency Portfolio.pdfCyaniclab : Software Development Agency Portfolio.pdf
Cyaniclab : Software Development Agency Portfolio.pdf
 
SOCRadar Research Team: Latest Activities of IntelBroker
SOCRadar Research Team: Latest Activities of IntelBrokerSOCRadar Research Team: Latest Activities of IntelBroker
SOCRadar Research Team: Latest Activities of IntelBroker
 
Abortion ^Clinic ^%[+971588192166''] Abortion Pill Al Ain (?@?) Abortion Pill...
Abortion ^Clinic ^%[+971588192166''] Abortion Pill Al Ain (?@?) Abortion Pill...Abortion ^Clinic ^%[+971588192166''] Abortion Pill Al Ain (?@?) Abortion Pill...
Abortion ^Clinic ^%[+971588192166''] Abortion Pill Al Ain (?@?) Abortion Pill...
 
Paketo Buildpacks : la meilleure façon de construire des images OCI? DevopsDa...
Paketo Buildpacks : la meilleure façon de construire des images OCI? DevopsDa...Paketo Buildpacks : la meilleure façon de construire des images OCI? DevopsDa...
Paketo Buildpacks : la meilleure façon de construire des images OCI? DevopsDa...
 
AI/ML Infra Meetup | Reducing Prefill for LLM Serving in RAG
AI/ML Infra Meetup | Reducing Prefill for LLM Serving in RAGAI/ML Infra Meetup | Reducing Prefill for LLM Serving in RAG
AI/ML Infra Meetup | Reducing Prefill for LLM Serving in RAG
 
In 2015, I used to write extensions for Joomla, WordPress, phpBB3, etc and I ...
In 2015, I used to write extensions for Joomla, WordPress, phpBB3, etc and I ...In 2015, I used to write extensions for Joomla, WordPress, phpBB3, etc and I ...
In 2015, I used to write extensions for Joomla, WordPress, phpBB3, etc and I ...
 
AI/ML Infra Meetup | ML explainability in Michelangelo
AI/ML Infra Meetup | ML explainability in MichelangeloAI/ML Infra Meetup | ML explainability in Michelangelo
AI/ML Infra Meetup | ML explainability in Michelangelo
 
GraphAware - Transforming policing with graph-based intelligence analysis
GraphAware - Transforming policing with graph-based intelligence analysisGraphAware - Transforming policing with graph-based intelligence analysis
GraphAware - Transforming policing with graph-based intelligence analysis
 
Vitthal Shirke Microservices Resume Montevideo
Vitthal Shirke Microservices Resume MontevideoVitthal Shirke Microservices Resume Montevideo
Vitthal Shirke Microservices Resume Montevideo
 
Developing Distributed High-performance Computing Capabilities of an Open Sci...
Developing Distributed High-performance Computing Capabilities of an Open Sci...Developing Distributed High-performance Computing Capabilities of an Open Sci...
Developing Distributed High-performance Computing Capabilities of an Open Sci...
 
BoxLang: Review our Visionary Licenses of 2024
BoxLang: Review our Visionary Licenses of 2024BoxLang: Review our Visionary Licenses of 2024
BoxLang: Review our Visionary Licenses of 2024
 
TROUBLESHOOTING 9 TYPES OF OUTOFMEMORYERROR
TROUBLESHOOTING 9 TYPES OF OUTOFMEMORYERRORTROUBLESHOOTING 9 TYPES OF OUTOFMEMORYERROR
TROUBLESHOOTING 9 TYPES OF OUTOFMEMORYERROR
 
How to Position Your Globus Data Portal for Success Ten Good Practices
How to Position Your Globus Data Portal for Success Ten Good PracticesHow to Position Your Globus Data Portal for Success Ten Good Practices
How to Position Your Globus Data Portal for Success Ten Good Practices
 
GlobusWorld 2024 Opening Keynote session
GlobusWorld 2024 Opening Keynote sessionGlobusWorld 2024 Opening Keynote session
GlobusWorld 2024 Opening Keynote session
 
A Comprehensive Appium Guide for Hybrid App Automation Testing.pdf
A Comprehensive Appium Guide for Hybrid App Automation Testing.pdfA Comprehensive Appium Guide for Hybrid App Automation Testing.pdf
A Comprehensive Appium Guide for Hybrid App Automation Testing.pdf
 
Studiovity film pre-production and screenwriting software
Studiovity film pre-production and screenwriting softwareStudiovity film pre-production and screenwriting software
Studiovity film pre-production and screenwriting software
 
Field Employee Tracking System| MiTrack App| Best Employee Tracking Solution|...
Field Employee Tracking System| MiTrack App| Best Employee Tracking Solution|...Field Employee Tracking System| MiTrack App| Best Employee Tracking Solution|...
Field Employee Tracking System| MiTrack App| Best Employee Tracking Solution|...
 
Corporate Management | Session 3 of 3 | Tendenci AMS
Corporate Management | Session 3 of 3 | Tendenci AMSCorporate Management | Session 3 of 3 | Tendenci AMS
Corporate Management | Session 3 of 3 | Tendenci AMS
 
WSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital Transformation
WSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital TransformationWSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital Transformation
WSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital Transformation
 

Top 30 Node.js interview questions

  • 1. TechieVarsity - Node.js Interview Questions Page 1 of 10 1 1. Why use Node.js? Node.js makes building scalable network programs easy. Some of its advantages include:  It offers a unified programming language and data type  Everything is asynchronous  It yields great concurrency  It is generally fast  It almost never blocks 2. 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 can be achieved as opposed to the typical thread-based implementation. 3. What are the functionalities of NPM in Node.js? NPM (Node package Manager) provides two functionalities:  Command line utility for installing packages, version management and dependency management of Node.js packages  Online repository for Node.js packages 4. What is the difference between Node.js and Ajax?  Ajax is primarily designed for dynamically updating a particular section of a page’s content, without having to update the entire page.  Node.js is used for developing client-server applications.  Node.js and Ajax (Asynchronous JavaScript and XML) are the advanced implementation of JavaScript. They all serve completely different purposes. 5. What are “streams” in Node.js? Explain the different types of streams present in Node.js. Streams are objects that allow reading of data from the source and writing of data to the destination as a continuous process. There are four types of streams.  to facilitate both read and write operations  is a form of Duplex stream that performs computations based on the available input  to facilitate the reading operation  to facilitate the writing operation 6. What are exit codes in Node.js? List some exit codes. Exit codes are specific codes that are used to end a “process” (a global object used to represent a node process).
  • 2. TechieVarsity - Node.js Interview Questions Page 2 of 10 2 Examples of exit codes include:  Internal Exception handler Run-Time Failure  Internal JavaScript Evaluation Failure  Unused  Uncaught Fatal Exception  Fatal Error  Non-function Internal Exception Handler 7. What are Globals in Node.js? Three keywords in Node.js constitute as Globals. These are:  Buffer – it is a class in Node.js to handle binary data.  Global – it represents the Global namespace object and acts as a container for all other objects.  Process – It is one of the global objects but can turn a synchronous function into an async callback. It can be accessed from anywhere in the code and it primarily gives back information about the application or the environment. 8. How can you avoid callback hells? There are lots of ways to solve the issue of callback hells:  modularization: break callbacks into independent functions  use a control flow library, like async  use generators with Promises  use async/await 9. What's wrong with the code snippet? new promise((resolve,reject) => { throw new Error(‘error’) then(console.log) The Solution As there is no catch after then. This way the error will be a silent one; there will be no indication of an error thrown. To fix it, you can do the following: new promise((resolve,reject) => { throw new Error(‘error’) then(console.log).catch(console.error)
  • 3. TechieVarsity - Node.js Interview Questions Page 3 of 10 3 10. What's output of the following code snippet? Answer: 2 11. Explain flow of the above code snippet  A new Promise is created, that will resolve to 1.  The resolved value is incremented with 1 (so it is 2 now), and returned instantly.  The resolved value is discarded, and an error is thrown.  The error is discarded, and a new value (1) is returned.  The execution did not stop after the catch, but before the exception was handled, it continued, and a new, incremented value (2) is returned.  The value is printed to the standard output.  This line won't run, as there was no exception. 12. What are perfect areas to use Node.js?  JSON APIs based Applications  Single Page Applications  I/O bound Applications  Data Streaming Applications  Data Intensive Real-time Applications (DIRT) 13. What Are The Key Features Of Node.Js?  There is an Active and vibrant community for the Node.js framework  No Buffering  Asynchronous event driven IO helps concurrent request handling  Fast in Code execution  Single Threaded but Highly Scalable  Node.js library uses JavaScript Promise.resolve(1) .then((x) => x +1) .then((x) => { throw new Error(‘My Error’) }) .catch(() => 1) .then ((x) => x +1 ) . then ((x) => console.log(x)) . catch(console.error)
  • 4. TechieVarsity - Node.js Interview Questions Page 4 of 10 4 14. When To Not Use Node.Js? We should not use it for cases where the application requires long processing time. If the server is doing some calculation, it won’t be able to process any other requests. Hence, Node.js is best when processing needs less dedicated CPU time. 15. List of most commonly used IDEs for developing node.js applications.  Cloud9.  JetBrains WebStorm.  JetBrains InteliJ IDEA.  Komodo IDE.  Eclipse.  Atom. 16. How to Get Post Data in Node.Js? 17. How to Make Post Request in Node.Js? 18. How to create Http server In Node.Js? app.use(express.bodyParser()); app.post(‘/’,function(request,response){ console.log(request.body.user); }); Var request = require(‘request’); Request. Post( ‘http://www.example.com/action’, { form: {key: ‘value’}}, Function (error, response, body) { If (!error && response.statusCode == 200) { console.log(body) } } var http = require(‘http’); var requestListener = function(request,response) {
  • 5. TechieVarsity - Node.js Interview Questions Page 5 of 10 5 19. What Is The Difference Between Nodejs, AJAX, And JQuery? Node.Js It is a server-side platform for developing client-server applications. AJAX (Asynchronous Javascript and XML) It is a client-side scripting technique, primarily designed for rendering the contents of a page without refreshing it. JQuery It is a famous JavaScript module with complements AJAX, DOM traversal, looping and so on. This library provides many useful functions to help in JavaScript development. 20. How many types of Streams are present in Node.js?  <Readable> – This is the Stream to be used for reading operation.  <Writable> – It facilitates the write operation.  <Duplex> – This Stream can be used for both the read and write operations.  <Transform> – It is a form of a duplex Stream, which performs the computations based on the available input. 21. What Is Package.Json?  It is a plain JSON (JavaScript Object Notation) text file which contains all metadata information about Node.js Project or application.  NPM (Node Package Manager) uses <package.json> file. It includes details of the Node.js application or package. This file contains a no. of different directives or elements. These directives guide NPM, about how to handle a module or package. response.writeHead(200, {‘Content-Type’:’text/plain’}); response.end(‘Welcome’); } Var server = http.createServer(requestListener); server.listen(8080);
  • 6. TechieVarsity - Node.js Interview Questions Page 6 of 10 6 22. Name some of the attributes of package.json? Following are the attributes of Package.json name– name of the package version– version of the package description– description of the package homepage– homepage of the package author– author of the package contributors– name of the contributors to the package dependencies– list of dependencies. npm automatically installs all the dependencies mentioned here in the node_module folder of the package. brepository– repository type and url of the package main– entry point of the package keywords– keywords 23. File IO operations Open a file using Node fs.open(path, flags[, mode], callback) Parameters Here is the description of the parameters used: 1. path– This is string having file name including path. 2. flags– Flag tell the behavior of the file to be opened. All possible values have been mentioned below. 3. mode– This sets the file mode (permission and sticky bits), but only if the file was created. It defaults to 0666, readable and writeable. 4. callback– This is the callback function which gets two arguments (err, fd). Read a file using Node fs.read(fd, buffer, offset, length, position, callback) This method will use file descriptor to read the file, if you want to read file using file name directly then you should use another method available. Parameters Here is the description of the parameters used: 1. fd– This is the file descriptor returned by file fs.open() method. 2. buffer– This is the buffer that the data will be written to. 3. offset– This is the offset in the buffer to start writing at. 4. length– This is an integer specifying the number of bytes to read. 5. position– This is an integer specifying where to begin reading from in the file. If position is null, data will be read from the current file position. 6. callback– This is the callback function which gets the three arguments, (err, bytesRead, buffer).
  • 7. TechieVarsity - Node.js Interview Questions Page 7 of 10 7 Write a file using Node fs.writeFile(filename, data[, options], callback) This method will over-write the file if file already exists. If you want to write into an existing file then you should use another method available. Parameters Here is the description of the parameters used: 1. path– This is string having file name including path. 2. data– This is the String or Buffer to be written into the file. 3. options– The third parameter is an object which will hold {encoding, mode, flag}. By default encoding is utf8, mode is octal value 0666 and flag is ‘w’ 4. callback– This is the callback function which gets a single parameter err and used to return error in case of any writing error. How will you close a file using Node? Following is the syntax of one of the methods to close an opened file: fs.close(fd, callback) Parameters Here is the description of the parameters used: 1. fd– This is the file descriptor returned by file fs.open() method. 2. callback– This is the callback function which gets no arguments other than a possible exception are given to the completion callback. How will you delete a file using Node? Following is the syntax of the method to delete a file: fs.unlink(path, callback) Parameters Here is the description of the parameters used: 1. path– This is the file name including path. 2. callback– This is the callback function which gets no arguments other than a possible exception are given to the completion callback. 24. How to handle the “Unhandled exceptions” in Node.js? It can be caught at the "Process level" by attaching a handler for uncaughtException event. Example: Process.on (‘uncaught Exception’, function (err) { Console.log(‘Caught exception: ‘ + err); }); 25. How to build a “Hello World” Application in Node.js?  Create a folder called ‘hello_world’.
  • 8. TechieVarsity - Node.js Interview Questions Page 8 of 10 8  Initialize the project with command ‘npm init’, this will create the package.json.  The project name only support URL friendly character and no longer support Capital letters.  This command will create the package.json. A. Install all dependencies using the command ‘npm install’. B. Start the project by running the command ‘node’. C. This will provide the option to write other things. D. Let’s print ‘Hello World!’. E. Every JavaScript function must return something, this console.log return undefined , therefore , the second line prints ‘undefined’. F. Create a file called ‘index.js’ inside ‘hello_world’ folder. From command line tool run ‘node index.js’. 26. Where to deploy node application?  Node.js app cannot be deployed on existing hosts like shared web hosting etc.  Use VPS or dedicated servers to install node and run your application.  The easiest way to deploy node application is to use a scalable service like Heroku, which is completely free and you only need to pay when you are using more resources. 27. Explain Node.js Code Execution Process? The steps of code execution are given below:  Clients send theirs request to Node.js Server.  Node.js Server receives those requests and places them into a processing Queue that is known as “Event Queue”.  Node.js uses JavaScript Event Loop to process each client request. This Event loop is an indefinite loop to receive requests and process them. Event Loop continuously checks for client’s requests placed in Event Queue. If requests are available, then it process them one by one.  If the client request does not require any blocking IO operations, then it process everything, prepare the response and send it back to the client.  If the client request requires some blocking IO operations like interacting with database, file system, external services then it uses C++ thread pool to process these operations. 28. What are core modules in Node.js? Assert It is used by Node.js for testing itself. Usage - require('assert'). Buffer It is used to perform operations on raw bytes of data which reside in memory. Usage - require('buffer'). Child Process It is used by node.js for managing child processes. It can be accessed with It Usage - require('child_process'). Cluster This module is used by Node.js to take advantage of multi-core systems, so that it can handle more load. Usage -require('cluster').
  • 9. TechieVarsity - Node.js Interview Questions Page 9 of 10 9 Console It is used to write data to console. Node.js has a Console object which contains functions to write data to console. Usage -require('console'). Crypto It is used to support cryptography for encryption and decryption. Usage - require('crypto'). Debugger It is used for code debugging. To use this, start Node.js with the debug argument and for debugging add debugger; statement in your code. DNS It is used to perform operations like lookup and resolve on domain names. Usage - require('dns'). Events It is used for events handling in node.js. In node.js, events are emitted by other node objects. Usage - require('events'). File System It is used to perform operations on files. Usage - require('fs'). HTTP It is used to create Http server and Http client. Usage - require('http'). Net It used to create TCP server and client which can communicate over a network using TCP protocol. Usage - require('net'). OS It is used to provide basic operating system related utility functions. Usage - require('os'). Path It is used to perform operations on paths of files. Usage - require('path'). Process It is a global object and provides information related to the program execution. Usage - require() method. Query String It is used to deal with query strings. Stream It is used to stream data between two entities. Usage - require('stream'). Timers All of the timer functions are global and deals with time. Usage - require() method. Url It is used for URL resolution and parsing. Usage - require('url'). Util It is primarily designed to support the needs of Node.js internal APIs. It is also useful for debugging. Usage - require('util'). 29. What are various error handling patterns in Node.js? There are following basic patterns you can use for errors handling in Node.js: • Try/Catch - The most commonly used way to handle errors in any programming language is try/catch blocks. Also, try/catch block executes in synchronous fashion; hence suitable for compiled languages like C#, Java etc. try { throw new Error('throw error'); } catch (e) { console.log(e); } Node.js to handle errors for synchronous code. • Callback – This way is used to handle errors in any callback without using nested try catch statements. In this way you have to pass a callback, function(err, result) which will be invoked when the asynchronous operation completes. Here err parameter returns the error and result is the result of completed operations, depending on whether the operation succeeded or failed. //request in express
  • 10. TechieVarsity - Node.js Interview Questions Page 10 of 10 10 app.get('/', function (req, res) { db.query('sql_query', function (err, result) { if (err) { res.writeHead(500); res.end(); console.log(err); } else { res.send(result); } }); }); 30. What are various node.js web development frameworks? The best and most powerful node.js web development frameworks to build real time and scalable web applications with ease are given below: MVC frameworks • Express • Koa • Hapi • Sails • Nodal 31. What are various node.js testing frameworks? The most popular node.js testing libraries and frameworks are given below: • Node.js assert • Mocha • Chai.js • Should.js • Nodeunit • Vows.js • Jasmine