Best Online Tutorials

SQL Tutorial

Free SQL Tutorial

SQL Interview Questions

SQL Practice Questions

SQL Tips & Tricks

SQL Errors

SQL Books

Angular Tutorial

Free Angular Tutorial

Angular Interview Questions

Angular Practice Questions

Angular Tips & Tricks

Angular Errors

Angular Books

Node.js Tutorial

Free Node.js Tutorial

Node.js Interview Questions

Node.js Practice Questions

Node.js Tips & Tricks

Node.js Errors

Node.js Books

React.js Tutorial

Free React.js Tutorial

React.js Interview Questions

React.js Practice Questions

React.js Tips & Tricks

React.js Errors

React.js Books

SSIS Tutorial

Free SSIS Tutorial

SSIS Interview Questions

SSIS Practice Questions

SSIS Tips & Tricks

SSIS Errors

SSIS Books

SEO Tutorial

Free SEO Tutorial

SEO Interview Questions

SEO Practice Questions

SEO Tips & Tricks

SEO Errors

SEO Books

Javascript Tutorial

Free Javascript Tutorial

Javascript Interview Questions

Javascript Practice Questions

Javascript Tips & Tricks

Javascript Errors

Javascript Books

MongoDB Tutorial

Free MongoDB Tutorial

MongoDB Interview Questions

MongoDB Practice Questions

MongoDB Tips & Tricks

MongoDB Errors

MongoDB Books

Next.js Tutorial

Free Next.js Tutorial

Next.js Interview Questions

Next.js Practice Questions

Next.js Tips & Tricks

Next.js Errors

Next.js Books

Node.js Interview Questions and Answers | Part 3 

Pooja Goel  |   Dec 30, 2019  |  Views: 150
pictures

Description:

21. What is callback hell in Node.js ?


Node.js works on the single thread non-blocking event loop, which passes another events as a callback next to be fired after any event completion.

Example of Callback Hell:

loadReocrds(function(a){
    loadFirstReocrds(a, function(b){
        loadSecondReocrds(b, function(c){ 
            loadThirdReocrds(c, function(d){ 
            loadFoutrhReocrds(d, function(e){ 
            ...
        });
        });
        });
    });
});

This type of calling callbacks in any event loop, causes callback hell in Node.js

This chain could be so long until the event loop ends, when there is no next callback event.



22. How do you prevent/fix/avoid callback hell ?


There are multiple techniques for dealing with callback hell.

Using Async.js
Using Promises
Using Async-Await


23. What are the available Web application framworks for Node.js ?


Express.js
Koa
Strapi
Sails.js
Hapi
FeathersJs
fastify
purpleecheerio-wave


24. Name the types of API functions in Node.js ?


There are two types of API functions in Node.js:

Asynchronous -> Non-blocking functions
Synchronous -> Blocking functions

 25. What is REPL in Node.js, Explain the role ?


REPL stands for Read-Eval-Print-Loop.

REPL is a Node shell - A virtual environment where a command is entered and the system responds with an output.

Node.js comes bundled with a REPL environment.

Read − Reads user's input.
Eval − evaluates the data.
Print − Prints the result.
Loop − Loops until the user presses the ctrl-c twice.


26. What are Commands & Keys for REPL ?


.break -  This command (or pressing the <ctrl>-C key combination) will abort further input or processing of that expression.
.clear -  Resets the REPL and clears any multi-line expression.
.exit -   Close the I/O stream, causing the REPL to exit.
.help -   Show this list of special commands.
.save -   Save the current REPL session to a file: > .save ./file/to/save.js
.load -   Load a file into the current REPL session. > .load ./file/to/load.js
.editor - Enter editor mode (<ctrl>-D to finish, <ctrl>-C to cancel).
ctrl + c   Terminate the current command.
ctrl + c (twice)  Terminate the Node REPL.
ctrl + d   Exit from the REPL.


27. Why we use underscore variable in REPL ?


The underscore variable is used to get the last result in REPL.
 
> var a = 20  
undefined  
> var b = 40  
undefined  
> a + b 
60  
> var add = _  
undefined  
> console.log(add)  
60  
undefined  


28. Difference between ajax and node.js ?


Ajax :

Ajax works on client-side to request on server and gets data as response from server then it renders on the client-side without refreshing the page.

It uses JavaScript to write syntax on clinet-side.

Node.js :

Nodejs is a JavaScript run time web application framework built on Google Chrome's V8 JavaScript engine.

It accepts the request sent from ajax and response with the expected web resources.

It also uses javascript to write syntax, but on server-side.


29. What is the difference between AngularJS and Node.js?


Node.js Interview Questions

Angularjs works on the client-side to handle the DOM manipulation and its events, it renders partial html views on the client-side without refreshing the page.

It uses JavaScript to write syntax on client-side.

Node.js :

Nodejs is a JavaScript run-time web application framework built on Google Chrome's V8 JavaScript engine.

It accepts the request sent from ajax and response with the expected web resources.

It also uses JavaScript to write syntax, but on server-side.


30. What are Globals in Node.js?


Global objects or variables are the one which are directly accessible to use anywhere in the whole application without importing any depndencies.

Global Objects Specific to Node.js:
  • __dirname - to get the current directory
  • __filename  to get the file name
  • exports - to make module or class accessable to anywhere in application
  • module - to declare a module
  • require() - to import libraries



Comments:
Content Contributor
Pooja Goel

Pooja Goel

Sr. Software developer at Damco Solutions Pvt. Ltd.  |   Noida, Uttar Pradesh, India

I am a sr. software developer working on technologies like SQL, SSIS, SSRS, DB2,Tableau, ASP.NET having 7 years of experience.


Read related articles

Node.js Interview Questions and Answers | Part 5

Pooja Goel  |   Dec 30, 2019  |  Views: 207

Node.js Interview Questions and Answers | Part 4

Pooja Goel  |   Dec 30, 2019  |  Views: 260

Node.js Interview Questions and Answers | Part 3

Pooja Goel  |   Dec 30, 2019  |  Views: 151

Node.js Interview Questions and Answers | Part 2

Pooja Goel  |   Dec 27, 2019  |  Views: 106

Node.js Interview Questions and Answers | Part 1

Pooja Goel  |   Dec 27, 2019  |  Views: 300

Want to sell your software ?-

If you want to sell your readymade software to the genuine clients or businessman, list your software with details and demo links.

  • Sell ERP
  • Sell Website Clones
  • Sell App Clones
  • Sell Readymade Portals
  • Sell Readymade Websites
  • Sell Mobile Apps
  • Sell Window Apps

Clients will find it using our advanced search filter and will contact you directly.

No any charge for the product lsiting.

Do you own a Company ?+

Property.sale

Buy or Sell Commercial Property+

Are you a freelancer ?+

Looking for a job ?+

Are you a Service Provider ?+

Are you a blogger ?+

Do you own an IT Institute ?+


Property.sale