Node JS Interview Questions
1 .
What is a passport in Node.js ?
Passport is a widely used middleware present in Node.js. It is primarily used for authentication, and it can easily fit into any Express.js-based web application.
With every application created, it will require unique authentication mechanisms. This is provided as single modules by using passport, and it becomes easy to assign strategies to applications based on requirements, thereby avoiding any sort of dependencies.
2 .
How does the DNS lookup function work in Node.js ?
The DNS lookup method uses a web address for its parameter and returns the IPv4 or IPv6 record, correspondingly.
There are other parameters such as the options that are used to set the input as an integer or an object. If nothing is provided here, both IPv4 and IPv6 are considered. The third parameter is for the callback function.
The syntax is:
dns.lookup(address, options, callback)
3 .
How is a test pyramid implemented using the HTML API in Node.js ?
Test pyramids are implemented by defining the HTML API. This is done using the following:
* A higher number of unit test cases
* A smaller number of integration test methods
* A fewer number of HTTP endpoint test cases
4 .
Why is assert used in Node.js ?
Assert is used to explicitly write test cases to verify the working of a piece of code. The following code snippet denotes the usage of assert:
var assert = require('assert');
function add(x, y) {
return x + y;
var result = add(3,5);
assert( result === 8, 'three summed with five is eight');