Node.js Interview Questions and answers

31. Can you access DOM in node?
Answer : No, you cannot access DOM in node.

32. Can you explain the difference between readFile vs createReadStream in Node.js ?
Answer : readFile – It will read the file completely into memory before making it available to the User.
createReadStream – It will read the file in chunks of the size which is specified before hand.

33. Using the event loop what are the tasks that should be done asynchronously?
Answer : a)I/O operations
b)Heavy computation
c)Anything requiring blocking

34. What are Error First Callbacks in Node.js
Answer : The “error-first” callback is s standard protocol for Node.js Callbacks which has a simple rule that the first argument for the callback function should be an error object. If the error argument is not null, then the operations was not successful, error has occurred and if the error argument is null then operation is successful.

35. What is the Use of underscore in Node.js?
Answer : To access the last expression, we have to use the (_) underscore/underline character.

36. List the tools and IDEs that are used for Node.js.
Answer :
Nodeclipse Enide Studio
JetBrains WebStorm
JetBrains InteliJ IDEA
MS Visual Studio

37. Why node.js is quickly gaining attention from JAVA programmers?
Answer : Node.js is quickly gaining attention as it is a loop based server for JavaScript. Node.js gives user the ability to write the JavaScript on the server, which has access to things like HTTP stack, file I/O, TCP and databases.

38. Explain how does Node.Js Work?
Answer : A Node.js application creates a single thread on its invocation. Whenever Node.js receives a request, it first completes its processing before moving on to the next request.
Node.js works asynchronously by using the event loop and callback functions, to handle multiple requests coming in parallel. An Event Loop is a functionality which handles and processes all your external events and just converts them to a callback function. It invokes all the event handlers at a proper time. Thus, lots of work is done on the back-end, while processing a single request, so that the new incoming request doesn’t have to wait if the processing is not complete.

39. What are the different custom directive types in angularjs?
Answer : AngularJS supports a no. of different directives which also depend on the level we want to restrict them.
So in all, there are four different kinds of custom directives.
Element Directives (E)
Attribute Directives (A)
CSS Class Directives (C)
Comment Directives (M)

40. What is an error-first callback?
Answer : Error-first callbacks are essentially used to pass errors and data. By default, the first argument is always an error object, where the user needs to check if something is wrong.

Comments are closed here.