Node JS Interview Questions and Answers Set 6

51.What Is A Control Flow Function? What Are The Steps Does It Execute?

It is a generic piece of code which runs in between several asynchronous function calls is known as control flow function.

It executes the following steps.

  • Control the order of execution.
  • Collect data.
  • Limit concurrency.
  • Call the next step in the program.

52. How To Make Post Request In Node.Js?

Following code snippet can be used to make a Post Request in Node.js.

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)

}});

53. What do you understand by the term I/O?

I/O stands for input and output. It accesses anything outside of your application. It loaded into the machine memory to run the program, once the application starts.

54. How many types of API functions are available in Node.js?

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

  • Asynchronous, Non-blocking functions
  • Synchronous, Blocking functions

55. How can you avoid callbacks?

To avoid callbacks, you can use any one of the following options:

  • You can use modularization. It breaks callbacks into independent functions.
  • You can use promises.
  • You can use yield with Generators and Promises.

NODE JS & CERTIFICATION
Weekend / Weekday Batch

56. Does Node.js provide Debugger?

Yes, Node.js provides a simple TCP based protocol and built-in debugging client. For debugging your JavaScript file, you can use debug argument followed by the js file name you want to debug.

Syntax:

node debug [script.js | -e “script” | <host>:<port>]

57. What tools can be used to assure a consistent style in Node.js?

Following is a list of tools that can be used in developing code in teams, to enforce a given style guide and to catch common errors using static analysis.

  • JSLint
  • JSHint
  • ESLint
  • JSCS

58. What is the difference between operational and programmer errors?

Operational errors are not bugs, but create problems with the system like request timeout or hardware failure. On the other hand, programmer errors are actual bugs

59. What is the use of a buffer class in Node.js?

The Node.js provides Buffer class to store raw data similar to an array of integers but corresponds to a raw memory allocation outside the V8 heap. It is a global class and can be accessed in an application without importing a buffer module. Buffer class is used because pure JavaScript is not compatible with binary data. So, when dealing with TCP streams or the file system, it’s necessary to handle octet streams.

60. What does Node.js TTY module contains?

The Node.js TTY module contains tty.ReadStream and tty.WriteStream classes. In most cases, there is no need to use this module directly. You have to used require (‘tty’) to access this module.

Syntax:

var tty = require(‘tty’);