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.
Posted Date:- 2021-08-27 07:55:49
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.
Posted Date:- 2021-08-27 07:54:43
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.
Posted Date:- 2021-08-27 07:54:05
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.
Posted Date:- 2021-08-27 07:53:26
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.
Posted Date:- 2021-08-27 07:52:43
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.
Posted Date:- 2021-08-27 07:52:02
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.
Posted Date:- 2021-08-27 07:51:15
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.
Posted Date:- 2021-08-27 07:50:32
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.
Posted Date:- 2021-08-27 07:48:49
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.
Posted Date:- 2021-08-27 07:48:03
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.
Posted Date:- 2021-08-27 07:47:11
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.
Posted Date:- 2021-08-27 07:45:51
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.
Posted Date:- 2021-08-27 07:43:30
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.
Posted Date:- 2021-08-27 07:42:56
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.
Posted Date:- 2021-08-27 07:42:27
NPM shrinkwrap lets you lock down the versions of installed packages and their descendant packages. 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.
Posted Date:- 2021-08-27 07:41:16
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
Posted Date:- 2021-08-27 07:39:39
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.
Posted Date:- 2021-08-27 07:38:42
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.
Posted Date:- 2021-08-27 07:37:54
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
Posted Date:- 2021-08-27 07:36:56
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.
Posted Date:- 2021-08-27 07:36:03
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.
Posted Date:- 2021-08-27 07:33:35
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.
Posted Date:- 2021-08-27 07:32:44
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.
Posted Date:- 2021-08-27 07:32:14
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
Posted Date:- 2021-08-27 07:30:03
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.
Posted Date:- 2021-08-27 07:29:09
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
Posted Date:- 2021-08-27 07:28:08
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
Posted Date:- 2021-08-27 07:27:40
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
Posted Date:- 2021-08-27 07:27:05
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.
Posted Date:- 2021-08-27 07:26:35
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.
Posted Date:- 2021-08-27 07:24:37
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.
Posted Date:- 2021-08-27 07:23:33
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.
Posted Date:- 2021-08-27 07:22:51
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
Posted Date:- 2021-08-27 07:21:12
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
Posted Date:- 2021-08-27 07:20:45
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
Posted Date:- 2021-08-27 07:19:33
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');
Posted Date:- 2021-08-27 07:18:49
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.
Posted Date:- 2021-08-27 07:17:57
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
Posted Date:- 2021-08-27 07:17:25
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.
Posted Date:- 2021-08-27 07:16:21
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.
Posted Date:- 2021-08-27 07:15:40
Express is a flexible Node.js web application framework that provides a wide set of features to develop both web and mobile applications
Posted Date:- 2021-08-27 07:14:24
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
Posted Date:- 2021-08-27 07:13:58
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.
Posted Date:- 2021-08-27 07:13:26
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.
Posted Date:- 2021-08-27 07:12:51
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);
Posted Date:- 2021-08-27 07:12:15
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');
Posted Date:- 2021-08-27 07:11:50
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.
Posted Date:- 2021-08-27 07:11:14
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');
Posted Date:- 2021-08-27 07:10:55
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
Posted Date:- 2021-08-27 07:08:44