

{"id":105288,"date":"2021-12-23T09:00:29","date_gmt":"2021-12-23T03:30:29","guid":{"rendered":"https:\/\/data-flair.training\/blogs\/?p=105288"},"modified":"2021-12-23T12:10:56","modified_gmt":"2021-12-23T06:40:56","slug":"nodejs-interview-questions-and-answers","status":"publish","type":"post","link":"https:\/\/data-flair.training\/blogs\/nodejs-interview-questions-and-answers\/","title":{"rendered":"Nodejs Interview Questions and Answers"},"content":{"rendered":"<p>In this article, you will have intervie3w questions and answers for different nodejs methods and modules. This includes theoretical as well as coding questions on node js.<\/p>\n<h3>Nodejs Interview Questions and Answers<\/h3>\n<p><strong>1) Demonstrate how a raw listener works programmatically.<\/strong><br \/>\nAns. Below is the code:<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">let EventEmitter = require('events');\r\nlet emitter = new EventEmitter();\r\nfunction event(arg) {\r\n    console.log('Welcome to', arg.name);\r\n}\r\nemitter.on('event', event)\r\nemitter.emit('event', { name: \"DataFlair\" })\r\nconsole.log(emitter.rawListeners('event'))\r\nemitter.off('event', event)<\/pre>\n<p><strong>2) Can variables be used in node js terminal? If yes, how?<\/strong><br \/>\nAns. Yes, we can store values in variables in node js terminal. There are two ways to store variables:<\/p>\n<p>Directly assigning to a variable Eg: a=20.<br \/>\nOr<br \/>\nVar a=20.<\/p>\n<p>When we use the first method then the value automatically gets printed, whereas when we use the second method \u201cundefined\u201d is initially shown. When we again access the variable, its correct value is shown.<\/p>\n<p><strong>3) Explain is it possible to use multiline statements in the repl terminal?<\/strong><br \/>\nAns. We can write multiline code in the repl terminal and then execute it in the repl terminal. To write such statements we use this \u2018{\u2018 bracket then we can press enter.<\/p>\n<p>Now you will see \u2018&#8230;\u2019 which indicates that you are in the multiline expressions and you can now write your statements.<\/p>\n<p><strong>4)What are the useful commands for node js terminal?<\/strong><br \/>\nAns<br \/>\n1) Use ctrl+c once: Terminate current command.<br \/>\n2) Use ctrl+c twice: Quit the repl terminal.<br \/>\n3) Use ctrl+d : Quit the repl terminal.<br \/>\n4) Up\/down key: Shows previous commands.<br \/>\n5) Tab key: View current commands<br \/>\n6) .help: Gives a list of all commands that it supports<br \/>\n7) .clear: Exits the multiline expression.<br \/>\n8) .break: Exits from multiline command<br \/>\n9) .save \u201cfilename\u201d: Saves the current repl as a file.<br \/>\n10) .load \u201cfilename\u201d: Loads a file into repl terminal<\/p>\n<p><strong>5) What are the timing features of node js?<\/strong><br \/>\nAns<\/p>\n<ul>\n<li>setTimeout\u2013 implements delays in code execution.<\/li>\n<li>setInterval\u2013 runs a code block multiple times.<\/li>\n<li>setImmediate\u2013 sets the execution of the code at the end of the event loop cycle.<\/li>\n<li>process.nextTick \u2013 sets the execution of code at the beginning of the next event loop cycle<\/li>\n<\/ul>\n<p><strong>6)What are the main advantages of promises over callback?<\/strong><br \/>\nAns Promises get an object to decide the action that needs to be done after the async task gets complete. This gives more manageable code and reduces callback hell. It also provides better error handling and asynchronous codes easily.<\/p>\n<p><strong>7) What is call back hell?<\/strong><br \/>\nAns.When a call back function is passed inside a function and again in the callback function there exists another call back function and so on.Then the code becomes unreadable and not maintainable the code goes on shifting to right side. So callback hell is a situation when a function takes a callback which inturn takes another callback function and so on.<\/p>\n<p><strong>8) How to use a formidable module to upload the file?<\/strong><br \/>\nAns. We have to include it using the require function. The below code demonstrates how to use formidable module to upload the file<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">let http = require('http');\r\nhttp.createServer(function (req, res) {\r\n    res.writeHead(200, { 'Content-Type': 'text\/html' });\r\n    res.write('&lt;form action=\"fileupload\" method=\"post\" enctype=\"multipart\/form-data\"&gt;');\r\n    res.write('&lt;input type=\"file\" name=\"filetoupload\"&gt;');\r\n    res.write('&lt;input type=\"submit\"&gt;');\r\n    res.write('&lt;\/form&gt;');\r\n    return res.end();\r\n}).listen(5000);<\/pre>\n<p><strong>9) If we want to use a hosted api for sending emails what method should we use?<\/strong><br \/>\nAns. It allows us to send email from our program using an API. We can use the API to handle sending and delivering the email. These APIs give a reliable service which can be used in our program easily with better functionality. One disadvantage of this method is that we have to rely on third parties for sending mails.<\/p>\n<p><strong>10) Why should we not use a transactional email api?<\/strong><br \/>\nAns: Mainly because of the below reasons we should not prefer transactional email api<\/p>\n<ul>\n<li>We have to rely on third-party for sending mails<\/li>\n<li>We have to separately integrate each channel.<\/li>\n<li>You don&#8217;t have ownership for the email service.<\/li>\n<\/ul>\n<p><strong>11) Differentiate between synchronous and async functions.<\/strong><br \/>\nAns Functions that do not block other codes until it is completely executed are called asynchronous function.<br \/>\nSynchronous function blocks the thread until this function executes completely.<\/p>\n<p>Reading a file in asynchronous mode will not block other functions but if we use a synchronous method to read a file then all other functions will get blocked.<\/p>\n<p><strong>12) Differentiate between blocking and non blocking callbacks.<\/strong><br \/>\nAns. Codes that block other functions are known as blocking callbacks. Non-blocking callbacks are those callbacks that do not block the execution of other callbacks.<\/p>\n<p><strong>13) Provide some standard methods of buffer in nodejs.<\/strong><br \/>\nAns<\/p>\n<ul>\n<li>\n<h4>Compare two buffers:<\/h4>\n<p>We can compare more than one buffer using the buffer.compare(buf1,buf2) function.<\/li>\n<li>\n<h4>Check isBuffer:<\/h4>\n<p>In order to know if the given object is a buffer or not we use the buffer.isBuffer(object) function.<\/li>\n<li>\n<h4>Check isEncoding:<\/h4>\n<p>If we want to check encoding we use isEncoding function. It returns true if the encoding is a valid encoding.<\/li>\n<\/ul>\n<p><strong>14) Describe the various stream types?<\/strong><br \/>\nAns.<\/p>\n<p>1. <strong>Readable stream:<\/strong> Used for receiving and reading the data in an ordered manner.<br \/>\n2.<strong> Writable stream:<\/strong> Used for sending data in an ordered manner.<br \/>\n3. <strong>Duplex stream:<\/strong> We can send in and receive data together.<br \/>\n4. <strong>Transform stream:<\/strong> Is used to make modification in the data. It works in duplex mode.<\/p>\n<p><strong>15) Why should we use a multichannel notification channel for sending email and at the same time why we should avoid it?<\/strong><br \/>\nAns. Why to use it:<\/p>\n<ul>\n<li>Easy to integrate with node js application.<\/li>\n<li>Even non-technical people can edit the content.<\/li>\n<li>Third party will maintain the email system<\/li>\n<\/ul>\n<p>The main reason for avoiding it is that we have to rely on a third-party for sending mails.<\/p>\n<h3>Summary:<\/h3>\n<p>This article covered some of the most frequently asked nodejs questions Hope you have liked the node js interview questions. Do check out the other nodejs quiz and interview questions to test your knowledge.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>In this article, you will have intervie3w questions and answers for different nodejs methods and modules. This includes theoretical as well as coding questions on node js. Nodejs Interview Questions and Answers 1) Demonstrate&#46;&#46;&#46;<\/p>\n","protected":false},"author":5,"featured_media":105442,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[25259],"tags":[26131,26134],"class_list":["post-105288","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-node-js-tutorials","tag-nodejs-interview-questions","tag-nodejs-interview-questions-and-answers"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.4 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Nodejs Interview Questions and Answers - DataFlair<\/title>\n<meta name=\"description\" content=\"Check these latest interview questions and answers on Nodejs. These will help you crack your nodejs interview easily.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/data-flair.training\/blogs\/nodejs-interview-questions-and-answers\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Nodejs Interview Questions and Answers - DataFlair\" \/>\n<meta property=\"og:description\" content=\"Check these latest interview questions and answers on Nodejs. These will help you crack your nodejs interview easily.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/data-flair.training\/blogs\/nodejs-interview-questions-and-answers\/\" \/>\n<meta property=\"og:site_name\" content=\"DataFlair\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/DataFlairWS\/\" \/>\n<meta property=\"article:published_time\" content=\"2021-12-23T03:30:29+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2021-12-23T06:40:56+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2021\/12\/nodejs-interview-questions-and-answers.webp\" \/>\n\t<meta property=\"og:image:width\" content=\"1200\" \/>\n\t<meta property=\"og:image:height\" content=\"628\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/webp\" \/>\n<meta name=\"author\" content=\"DataFlair Team\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@DataFlairWS\" \/>\n<meta name=\"twitter:site\" content=\"@DataFlairWS\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"DataFlair Team\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"5 minutes\" \/>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Nodejs Interview Questions and Answers - DataFlair","description":"Check these latest interview questions and answers on Nodejs. These will help you crack your nodejs interview easily.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/data-flair.training\/blogs\/nodejs-interview-questions-and-answers\/","og_locale":"en_US","og_type":"article","og_title":"Nodejs Interview Questions and Answers - DataFlair","og_description":"Check these latest interview questions and answers on Nodejs. These will help you crack your nodejs interview easily.","og_url":"https:\/\/data-flair.training\/blogs\/nodejs-interview-questions-and-answers\/","og_site_name":"DataFlair","article_publisher":"https:\/\/www.facebook.com\/DataFlairWS\/","article_published_time":"2021-12-23T03:30:29+00:00","article_modified_time":"2021-12-23T06:40:56+00:00","og_image":[{"width":1200,"height":628,"url":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2021\/12\/nodejs-interview-questions-and-answers.webp","type":"image\/webp"}],"author":"DataFlair Team","twitter_card":"summary_large_image","twitter_creator":"@DataFlairWS","twitter_site":"@DataFlairWS","twitter_misc":{"Written by":"DataFlair Team","Est. reading time":"5 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/data-flair.training\/blogs\/nodejs-interview-questions-and-answers\/#article","isPartOf":{"@id":"https:\/\/data-flair.training\/blogs\/nodejs-interview-questions-and-answers\/"},"author":{"name":"DataFlair Team","@id":"https:\/\/data-flair.training\/blogs\/#\/schema\/person\/7f83c342f5d1632d6f7b4b0b0f447823"},"headline":"Nodejs Interview Questions and Answers","datePublished":"2021-12-23T03:30:29+00:00","dateModified":"2021-12-23T06:40:56+00:00","mainEntityOfPage":{"@id":"https:\/\/data-flair.training\/blogs\/nodejs-interview-questions-and-answers\/"},"wordCount":910,"commentCount":0,"publisher":{"@id":"https:\/\/data-flair.training\/blogs\/#organization"},"image":{"@id":"https:\/\/data-flair.training\/blogs\/nodejs-interview-questions-and-answers\/#primaryimage"},"thumbnailUrl":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2021\/12\/nodejs-interview-questions-and-answers.webp","keywords":["Nodejs Interview Questions","Nodejs Interview Questions and Answers"],"articleSection":["Node Js Tutorials"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/data-flair.training\/blogs\/nodejs-interview-questions-and-answers\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/data-flair.training\/blogs\/nodejs-interview-questions-and-answers\/","url":"https:\/\/data-flair.training\/blogs\/nodejs-interview-questions-and-answers\/","name":"Nodejs Interview Questions and Answers - DataFlair","isPartOf":{"@id":"https:\/\/data-flair.training\/blogs\/#website"},"primaryImageOfPage":{"@id":"https:\/\/data-flair.training\/blogs\/nodejs-interview-questions-and-answers\/#primaryimage"},"image":{"@id":"https:\/\/data-flair.training\/blogs\/nodejs-interview-questions-and-answers\/#primaryimage"},"thumbnailUrl":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2021\/12\/nodejs-interview-questions-and-answers.webp","datePublished":"2021-12-23T03:30:29+00:00","dateModified":"2021-12-23T06:40:56+00:00","description":"Check these latest interview questions and answers on Nodejs. These will help you crack your nodejs interview easily.","breadcrumb":{"@id":"https:\/\/data-flair.training\/blogs\/nodejs-interview-questions-and-answers\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/data-flair.training\/blogs\/nodejs-interview-questions-and-answers\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/data-flair.training\/blogs\/nodejs-interview-questions-and-answers\/#primaryimage","url":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2021\/12\/nodejs-interview-questions-and-answers.webp","contentUrl":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2021\/12\/nodejs-interview-questions-and-answers.webp","width":1200,"height":628,"caption":"nodejs interview questions and answers"},{"@type":"BreadcrumbList","@id":"https:\/\/data-flair.training\/blogs\/nodejs-interview-questions-and-answers\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Blog Home","item":"https:\/\/data-flair.training\/blogs\/"},{"@type":"ListItem","position":2,"name":"Node Js Tutorials","item":"https:\/\/data-flair.training\/blogs\/category\/node-js-tutorials\/"},{"@type":"ListItem","position":3,"name":"Nodejs Interview Questions and Answers"}]},{"@type":"WebSite","@id":"https:\/\/data-flair.training\/blogs\/#website","url":"https:\/\/data-flair.training\/blogs\/","name":"DataFlair","description":"Learn Today. Lead Tomorrow.","publisher":{"@id":"https:\/\/data-flair.training\/blogs\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/data-flair.training\/blogs\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/data-flair.training\/blogs\/#organization","name":"DataFlair","url":"https:\/\/data-flair.training\/blogs\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/data-flair.training\/blogs\/#\/schema\/logo\/image\/","url":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2016\/07\/Data-Flair.png","contentUrl":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2016\/07\/Data-Flair.png","width":106,"height":48,"caption":"DataFlair"},"image":{"@id":"https:\/\/data-flair.training\/blogs\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/DataFlairWS\/","https:\/\/x.com\/DataFlairWS","https:\/\/www.linkedin.com\/company\/dataflair-web-services-pvt-ltd\/","https:\/\/www.youtube.com\/user\/DataFlairWS"]},{"@type":"Person","@id":"https:\/\/data-flair.training\/blogs\/#\/schema\/person\/7f83c342f5d1632d6f7b4b0b0f447823","name":"DataFlair Team","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/secure.gravatar.com\/avatar\/4cf3a74600d131330b8c481d519afd1574093ed89f6d3396a95393ad223eb7cd?s=96&d=mm&r=g","url":"https:\/\/secure.gravatar.com\/avatar\/4cf3a74600d131330b8c481d519afd1574093ed89f6d3396a95393ad223eb7cd?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/4cf3a74600d131330b8c481d519afd1574093ed89f6d3396a95393ad223eb7cd?s=96&d=mm&r=g","caption":"DataFlair Team"},"description":"DataFlair Team creates expert-level guides on programming, Java, Python, C++, DSA, AI, ML, data Science, Android, Flutter, MERN, Web Development, and technology. Our goal is to empower learners with easy-to-understand content. Explore our resources for career growth and practical learning.","url":"https:\/\/data-flair.training\/blogs\/author\/dfteam1\/"}]}},"amp_enabled":true,"_links":{"self":[{"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/posts\/105288","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/users\/5"}],"replies":[{"embeddable":true,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/comments?post=105288"}],"version-history":[{"count":3,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/posts\/105288\/revisions"}],"predecessor-version":[{"id":105443,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/posts\/105288\/revisions\/105443"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/media\/105442"}],"wp:attachment":[{"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/media?parent=105288"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/categories?post=105288"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/tags?post=105288"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}