Node js interview question set 2/Node JS Interview Questions and Answers for Freshers & Experienced

What is dynamic memory management?

Dynamic memory management is a technique in which storage units are allocated based on the requirements continuously. Using dynamic memory allocations, individual data structures can be either stored separately or combined to form entities called composites. These composites can be worked on when required.

What is the meaning of FIFO?

FIFO, also known as First in, First out, is a way of representing a data operation on factors such as how data is accessed and in what order. Here, the data that is first put into the list will be the first entity to exit from the ordered data structure.

What is a Binary Search Tree?

A binary search tree is a data structure that stores data in a very efficient manner. It consists of two primary nodes from the root node. The main thing here is that the values of the nodes in the left sub-tree are less in number than the value of the root node, and the values of the nodes on the right of the root node are correspondingly higher than the root. Also, individually both of these left and right sub-trees are their own binary search trees at all points of time.

Are linked lists Linear or Non-linear Data Structures?

Linked lists are considered to be the best of both worlds here. Based on usage, if it is a storage policy, then it can be considered as non-linear. Whereas, if a person is considering it based on retrieval strategies, then it can be considered linear.

Next up on these Data Structure questions, you need to understand a little bit about a Binary Search Tree.

What are multi-dimensional arrays?

Multi-dimensional arrays are arrays that span across more than one dimension. This means that they will have more than one index variable for every point of storage. This is primarily used in cases where data cannot be represented or stored using only one dimension.

What is the working of LIFO?

LIFO stands for the Last in, First out access order. It is directly corresponding to how the data can be worked on and modified. The data entity that is stored or pushed in last is the first one to be worked on at any point in time. If there is a requirement to access the very first element stored, then first you have to retrieve all of the data that came in after that element.

How does binary search work?

Binary search is used when there is primarily a criterion of efficiency. It involves working on the already ordered data, which is sorted either in ascending or in descending order. To begin with, the middle element of the array is found out, and the search begins from there. The array is searched in two parts based on the search value being higher or lower than the middle element. It is key to know the order of the arrangement to help search the value accordingly.

What are the types of searching used in Data Structures?

The two primary methods of searching are linear search and binary search.

Linear search involves iterating over a data unit in order to perform the required operation.

Binary search is more efficient in a way that it has the ability to split the data unit into chunks and then perform a search operation.

Do you have any certification to boost your candidature for this Node.js role?

It is always advantageous to have a certification in the technology that you’re applying for. This gives the interviewer the impression that you have worked on the technology and that you are serious about using it for your career growth. More than this, it adds immense value to your resume and your knowledge on the topic at the same time.

If you are looking forward to becoming proficient in Web Development, make sure to check out Intellipaat’s latest offerings for the Web Development Online Course. With these programs, you can become an expert in Web Development and earn a course certificate as well.

Do you have any experience working in the same industry like ours?

With this question, the interviewer is trying to assess if you’ve had any previous work experience or internship experience where you dealt with similar working environments or technologies. This line of questioning can be easily answered based on your previous experiences. Make sure to keep it concise and detailed as required when answering this question.

Do you have any past Node.js work experience?

This question is common among Node.js interviews. Make sure to answer it to the best of your abilities, and do not bloat but give your honest experiences and explain how you’ve used Node.js before. This is used as a measure to see if you have had any hands-on experience with the language in a working environment before.

Why do you think you are the right fit for this Node.js role?

Here, the interviewer wants to know your understanding of the job role and the company architecture and your knowledge on the topic. While answering this question, it would add immensely if you knew the job description in detail and the basic usage of the technology in the company. The answer can be further elaborated on how your interests align with the technology, job, and company.

What is the difference between fork() and spawn() methods in Node.js?

Spawn command is designed to run system commands. When Spawn command is used, you send it a system command that is processed on its own but no further code is processed within your node process. Whereas, Fork is a special instance of Spawn. This means that you can create workers for running the exact same Node code base or maybe a different module for a particular task.

What is the use of EventEmitter in Node.js?

Every single object in Node.js that emits is nothing but an instance of the EventEmitter class. These objects have a function that is used to allow the attachment between the objects and the named events.

Synchronous attachments of the functions are done when the EventEmitter object emits an event.

How to get information about a file in Node.js?

The fs.stat function is used to get the required information from a file.

The syntax is as follows:

fs.stat(path, callback)
where,

Path: The string that has the path to the name
Callback: The callback function where stats is an object of fs.stats
Next up among these Node.js interview questions, you need to understand about DNS lookup.

Why npm shrinkwrap is useful?

NPM shrinkwrap lets you lock down the ver­sions of installed pack­ages and their descen­dant pack­ages. It helps you use same package versions on all environments (development, staging, production) and also improve download and installation speed. Having same versions of packages on all environments can help you test systems and deploy with confidence. If all tests pass on one machine, you can be sure that it will pass on all other because you know that you use same code!

npm shrinkwrap
It should create new npm-shrinkwrap.json file with information about all packages you use.

What are some of the flags used in the read/write operations in files?

Node.js uses several flags in the read/write operations in files. Below mentioned are some of the flags:

> r : open file for reading
> r+ : open file for reading and writing
> rs : Open file for reading in synchronous mode
> w : Open file for writing
> a : Open file for appending

What are the security mechanisms available in Node.js?

Node.js is equipped with various security mechanism, some are mentioned below:

> Certified Security Modules can assess any third part codes that are catered into the software.
> Regular updates of versions are made in Node.js so that it does not become vulnerable to hackers.
> Curated Screening Register is a kind of quality control system through which every new package code or software is passed to maintain safety before downloading.

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.

Describe Node.js exit codes.

Exit codes in Node.js are particular codes which help in finishing the processes. This may also include global objects. Some examples of exit code in Node.js are-

> Internal JavaScript Evaluation Failure
> Fatal Error
> Internal Exception
> Handler Run-time failure
> Unused
> Uncaught fatal exception

Explain the concept of middleware in Node.js.

Middleware is a function that has the access to the requested object, requested response and the next function in the application’s request-response cycle. The middleware function can perform multiple tasks such as; execute code, make changes to the request and the response objects, end the request-response cycle and call the next middleware in the stack.

What are the challenges with Node.js?

Even though Node.js is one of the most popular and widely used open sources software, it has its own challenges-

> The performance of Node.js is restricted by the heavy computation tasks and also till date Node.js cannot process CPU bound tasks.
> There might be Callback issues because of their asynchronous nature.
> Despite having stable modules, Node.js still has immaturity within tools. There are several tools in the npm registry that aren’t structured well enough.

How will you debug an application in Node.js?

Debugging means relieving your code from any error. Identifying an error can take up many hours for which Node.js has a great tool that can help finding the error.

Open the initial file (typically index.js), activate the Run and Debug pane, and click the Run and Debug Node.js (F5) button. The debugging screen is similar to Chrome DevTools with a Variables, Watch, Call stack, Loaded scripts, and Breakpoints list.

Why is Node.js quickly gaining attention from JAVA programmers?

The reason behind Node.js rapidly gaining popularity is its loop-based server for JavaScript. Node.js provides the developer the facility to write JavaScript on the server.

How would you connect a MongoDB database to Node.js?

To create a database in MongoDB:

1. Start by creating a MongoClient object
2. Specify a connection URL with the correct IP address and the name of the database you want to create

What is the use of the crypto module in Node.js?

The crypto module in Node.js is used to provide users with cryptographic functionalities. This provides them with a large number of wrappers to perform various operations such as cipher, decipher, signing, and hashing operations.

How would you connect a MongoDB database to Node.js?

To create a database in MongoDB:

Start by creating a MongoClient object
Specify a connection URL with the correct IP address and the name of the database you want to create

What are the different types of HTTP requests?

HTTP defines a set of request methods used to perform desired actions. The request methods include:

GET: Used to retrieve the data

POST: Generally used to make a change in state or reactions on the server

HEAD: Similar to the GET method, but asks for the response without the response body

DELETE: Used to delete the predetermined resource

How can you listen on port 80 with Node?

Instead of running on port 80 we can redirect port 80 to your application's port (>1024) using

iptables -t nat -I PREROUTING -p tcp --dport 80 -j REDIRECT --to-port 3000

Is Node.js entirely based on a single-thread?

Yes, it is true that Node.js processes all requests on a single thread. But it is just a part of the theory behind Node.js design. In fact, more than the single thread mechanism, it makes use of events and callbacks to handle a large no. of requests asynchronously.

Moreover, Node.js has an optimized design which utilizes both JavaScript and C++ to guarantee maximum performance. JavaScript executes at the server-side by Google Chrome v8 engine. And the C++ lib UV library takes care of the non-sequential I/O via background workers.

To explain it practically, let’s assume there are 100s of requests lined up in Node.js queue. As per design, the main thread of Node.js event loop will receive all of them and forwards to background workers for execution. Once the workers finish processing requests, the registered callbacks get notified on event loop thread to pass the result back to the user.

What is chaining process in Node.js?

It is an approach to connect the output of one stream to the input of another stream, thus creating a chain of multiple stream operations.

What is JIT and how is it related to Node.js?

Node.js has depended on the V8 JavaScript engine to provide code execution in the language. The V8 is a JavaScript engine built at the google development center, in Germany. It is open source and written in C++. It is used for both client side (Google Chrome) and server side (node.js) JavaScript applications. A central piece of the V8 engine that allows it to execute JavaScript at high speed is the JIT (Just In Time) compiler. This is a dynamic compiler that can optimize code during runtime. When V8 was first built the JIT Compiler was dubbed FullCodegen. Then, the V8 team implemented Crankshaft, which included many performance optimizations that FullCodegen did not implement.

The V8 was first designed to increase the performance of the JavaScript execution inside web browsers. In order to obtain speed, V8 translates JavaScript code into more efficient machine code instead of using an interpreter. It compiles JavaScript code into machine code at execution by implementing a JIT (Just-In-Time) compiler like a lot of modern JavaScript engines such as SpiderMonkey or Rhino (Mozilla) are doing. The main difference with V8 is that it doesn’t produce bytecode or any intermediate code.

How does Node.js support multi-processor platforms, and does it fully utilize all processor resources?

Since Node.js is by default a single thread application, it will run on a single processor core and will not take full advantage of multiple core resources. However, Node.js provides support for deployment on multiple-core systems, to take greater advantage of the hardware. The Cluster module is one of the core Node.js modules and it allows running multiple Node.js worker processes that will share the same port.

The cluster module helps to spawn new processes on the operating system. Each process works independently, so you cannot use shared state between child processes. Each process communicates with the main process by IPC and pass server handles back and forth.

Cluster supports two types of load distribution:

1. The main process listens on a port, accepts new connection and assigns it to a child process in a round robin fashion.
2. The main process assigns the port to a child process and child process itself listen the port.

What is a reactor pattern in Node.js?

A reactor pattern is a concept of non-blocking I/O operations. This pattern provides a handler that is associated with each I/O operation. As soon as an I/O request is generated, it is then submitted to a demultiplexer

What is piping in Node.js?

Piping is a mechanism used to connect the output of one stream to another stream. It is normally used to retrieve data from one stream and pass output to another stream

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:

1. A higher number of unit test cases
2. A smaller number of integration test methods
3. A fewer number of HTTP endpoint test cases

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');

How do we implement async in Node.js?

As shown below, the async code asks the JavaScript engine running the code to wait for the request.get() function to complete before moving on to the next line for execution.

Explain asynchronous and non-blocking APIs in Node.js.

1. All Node.js library APIs are asynchronous, which means they are also non-blocking
2. A Node.js-based server never waits for an API to return data. Instead, it moves to the next API after calling it, and a notification mechanism from a Node.js event responds to the server for the previous API call

What is the command that is used in node.js to import external libraries?

Command “require” is used for importing external libraries, for example, “var http=require (“http”)”. This will load the http library and the single exported object through the http variable.

How does Node.js handle child threads?

Node.js is a single threaded language which in background uses multiple threads to execute asynchronous code. Node.js is non-blocking which means that all functions ( callbacks ) are delegated to the event loop and they are ( or can be ) executed by different threads. That is handled by Node.js run-time.

1. Nodejs Primary application runs in an event loop, which is in a single thread.
2. Background I/O is running in a thread pool that is only accessible to C/C++ or other compiled/native modules and mostly transparent to the JS.
3. Node v11/12 now has experimental worker_threads, which is another option.
4. Node.js does support forking multiple processes ( which are executed on different cores ).
5. It is important to know that state is not shared between master and forked process.
6. We can pass messages to forked process ( which is different script ) and to master process from forked process with function send.

What is the Express.js package?

Express is a flexible Node.js web application framework that provides a wide set of features to develop both web and mobile applications

What is the package.json file?

The package.json file is the heart of a Node.js system. This file holds the metadata for a particular project. The package.json file is found in the root directory of any Node application or module

This is what a package.json file looks like immediately after creating a Node.js project using the command: npm init

What does it mean “non-blocking” in node.js?

In node.js “non-blocking” means that its IO is non-blocking. Node uses “libuv” to handle its IO in a platform-agnostic way. On windows, it uses completion ports for unix it uses epoll or kqueue etc. So, it makes a non-blocking request and upon a request, it queues it within the event loop which call the JavaScript ‘callback’ on the main JavaScript thread.

What are the Challenges with Node.js?

Emphasizing on the technical side, it’s a bit of challenge in Node.js to have one process with one thread to scale up on multi core server.

Is cryptography supported in Node.js?

Yes, Node.js does support cryptography through a module called Crypto. This module provides various cryptographic functionalities like cipher, decipher, sign and verify functions, a set of wrappers for open SSL’s hash HMAC etc. For example:

Syntax:

const crypto = require'crypto');
const secret = 'akerude';
const hash = crypto.createHmac('swaEdu', secret).update('Welcome to Edureka').digest('hex');
console.log(hash);

What do you understand by an Event Emitter in Node.js?

EventEmitter is a Node.js class that includes all the objects that are capable of emitting events. These objects contain an eventEmitter.on() function through which more than one function can be attached to the named events that are emitted by the object. Whenever an EventEmitter object throws an event, all the attached functions to that specific event are invoked synchronously. Below code shows how to us the EventEmitter in your application:


const EventEmitter = require('events');
class MyEmitter extends EventEmitter { }
const myEmitter = new MyEmitter();
myEmitter.on('event', () => {
console.log('an event occurred!');
});
myEmitter.emit('event');

Differentiate between Node.js vs Ajax?

The most basic difference between Node.js and Ajax that, Node.js is a server-side JavaScript whereas Ajax is a client-side technology. In simpler terms, Ajax is mostly used for updating or modifying the webpage contents without having to refresh it. On the other hand, Node.js is required to develop the server software that are typically executed by the servers instead of the web browsers.

Explain the concept of Punycode in Node.js?

In Node.js, Punycode is an encoding syntax that is used for converting Unicode (UTF-8) string of characters into a basic ASCII string of characters. It is important as the hostnames can only understand the ASCII characters. Thus, Node.js version 0.6.2 onwards, it was bundled up with the default Node package. If you want to use it with any previous versions, you can easily do that by using the following code:

Syntax:

punycode = require('punycode');

List down the various timing features of Node.js.

Node.js provides a Timers module which contains various functions for executing the code after a specified period of time. Below I have listed down the various functions provided by this module:

1. setTimeout/clearTimeout – Used to schedule code execution after a designated amount of milliseconds
2. setInterval/clearInterval – Used to execute a block of code multiple times
setImmediate/clearImmediate – Used to execute code at the end of the current event loop cycle
3. process.nextTick – Used to schedule a callback function that needs to be invoked in the next iteration of the Event Loop

Search
R4R Team
R4R provides Node JS Freshers questions and answers (Node JS Interview Questions and Answers) .The questions on R4R.in website is done by expert team! Mock Tests and Practice Papers for prepare yourself.. Mock Tests, Practice Papers,Node js interview question set 2,Node JS Freshers & Experienced Interview Questions and Answers,Node JS Objetive choice questions and answers,Node JS Multiple choice questions and answers,Node JS objective, Node JS questions , Node JS answers,Node JS MCQs questions and answers Java, C ,C++, ASP, ASP.net C# ,Struts ,Questions & Answer, Struts2, Ajax, Hibernate, Swing ,JSP , Servlet, J2EE ,Core Java ,Stping, VC++, HTML, DHTML, JAVASCRIPT, VB ,CSS, interview ,questions, and answers, for,experienced, and fresher R4r provides Python,General knowledge(GK),Computer,PHP,SQL,Java,JSP,Android,CSS,Hibernate,Servlets,Spring etc Interview tips for Freshers and Experienced for Node JS fresher interview questions ,Node JS Experienced interview questions,Node JS fresher interview questions and answers ,Node JS Experienced interview questions and answers,tricky Node JS queries for interview pdf,complex Node JS for practice with answers,Node JS for practice with answers You can search job and get offer latters by studing r4r.in .learn in easy ways .