Node.JS

Node.js is an open-source, cross-platform JavaScript run-time environment that executes JavaScript code outside of a browser. We have list down some important question and answers for fresher and professional to crack the job interviews.

Q.1 What do you understand by callback, in NodeJS?
Callback is a function that is to be executed after another function has finished executing  or called after a task is finished. It is asynchronous equivalent for a function. All APIs of Node are written is such a way that they supports callbacks.
Q.2 Explain secure coding.
Secure coding is the process of development of computer software in a way that protects against the accidental introduction of security vulnerabilities.
Q.3 What is static content?
Static content is basically any content that can be delivered to the end users without the need to be generated, modified, or processed.
Q.4 What is GIT?
Git is a free open source distributed version control system that is designed to handle small as well as large projects with speed and efficiency.
Q.5 Describe Reactor Pattern in Node.js?

Reactor Pattern is an idea of non-blocking I/O operations in Node.js. This pattern provides a handler(in case of Node.js, a callback function) that is associated with each I/O operation. When an I/O request is generated, it is submitted to a demultiplexer. This demultiplexer is a notification interface that is used to handle concurrency in non-blocking I/O mode and collects every request in form of an event and queues each event in a queue.

Thus, the demultiplexer provides the Event Queue. At the same time, there is an Event Loop which iterates over the items in the Event Queue. Every event has a callback function associated with it, and that callback function is invoked when the Event Loop iterates.

Q.6 Differentiate between process.nextTick() and setImmediate()?
The difference between process.nextTick() and setImmediate() is that process.nextTick() defers the execution of an action till the next pass around the event loop or it simply calls the callback function once the ongoing execution of the event loop is finished whereas setImmediate() executes a callback on the next cycle of the event loop and it gives back to the event loop for executing any I/O operations.
Q.7 What is event loop in JavaScript?
Event loop, as the name suggests is loop which runs in background listening for various event emitters.
Q.8 What is a callback in Node.js?
Callback is a piece of code which is passed as an argument to another function (say fn1) to execute the callback function (say fn2) after executing the function fn1. This is used to handle the asynchronous behaviour of javascript. The functionality of a callback can be imagined as somewhat analogous to Interfaces in JAVA.
Q.9 What is callback hell and how can it be avoided?
Callback hell refers to a coding pattern where there is a lot of nesting of callback functions. The code forms a pyramid like structure and it becomes difficult to debug. Callback hell refers to a coding pattern where there is a lot of nesting of callback functions. The code forms a pyramid like structure and it becomes difficult to debug. It can be avoided by: a. Using promises b. Yield operator and Generator functions from ES6 c. Modularizing code d. Using async library (http://caolan.github.io/async/)
Q.10 What is a Promise in Node.Js?
A promise is a method that eventually produces a value. Instead of passing a function as argument as with callbacks, “Once the result is received from an asynchronous operation then the required function is executed”. The required functions are never passed as arguments to the asynchronous operation. It has the form: callAsyncFunction() .then(firstFunction) .then(secondFunction) .then(thirdFunction) .then(fourthFunction);
Q.11 What are ACID properties wrt to a database?
ACID stands for Atomicity, Consistency, Isolation and Durability. Atomicity It means that either the record/document updates completely or does not update with respect to the operation. Consistency It implies that a transaction either creates a new and valid state of data, or, if any failure occurs, returns all data to its state before the transaction was started. Isolation Two or more simultaneous database queries should run independent of the other transactions. Durability Data once committed should be saved in memory so that even in case of system failure, data is not affected.
Q.12 Where and why should you not use NodeJS?
NodeJS should NOT be used where computations are CPU intensive. Eg: Data Analytics Server, Image Processing Servers, Video Processing Servers etc. NodeJS is meant for highly I/O-bound operations which does not require heavy CPU intensive operation/tasks.
Q.13 What is the relation of Node.js with JavaScript?
Node.js is not a JavaScript framework, many of its modules are written in JavaScript. - It allows the developers to create new modules in JavaScript. - Node.js is a virtual machine that leverages JavaScript as its scripting language to achieve high output.
Q.14 Can you provide some good examples of config file separation for dev and prod environments.

A perfect and flawless configuration setup should ensure: - keys can be read from file AND from environment variable - secrets are kept outside committed code - config is hierarchical for easier findability Consider the following config file:


Q.15 What is the use of Node.JS?
Node.JS is used primarily for non-blocking and event-driven servers, because its single-threaded nature. It is used for traditional web sites as well as back-end API services and was designed with real-time, push-based architectures in mind.
Q.16 What is a web application?
A web application is nothing but an application software running on a web server, unlike computer-based software programs that are run locally on the operating system of the device.
Q.17 How would you define Node.JS?
Node. js is actually a platform that is built on Chrome's JavaScript runtime for building fast and scalable network applications easily.
Q.18 What does DOM stand for?
DOM stands for Document Object Model that is a programming interface for HTML and XML documents. It basically represents the page so that programs can change the structure, style, and content of the document.
Q.19 What is the use of Xpath?
XPath provides syntax so as to define part of an XML document. Besides, XPath Expression is a query language that is used to select part of the XML document based on the query string.
Q.20 Name the three parts of DOM.
The three parts into which DOM is separated are: Core, HTML, and XML.
Q.21 Why do we use XML?
Web agents and robots become more efficient and productive with the use of XML. Some of its general applications includes provision of a standard method for accessing information, hence, making it easier for applications and devices of all kinds to transmit, use, store, and display data.
Q.22 What do you know about node CLI?
CLIs built in Node. js enable the automation of repetitive tasks while leveraging the vast Node. js ecosystem. Moreover, with the help of package managers like npm and yarn , these can be distributed and consumed across multiple platforms easily.
Q.23 What is NPM?
NPM is the package manager for the Node JavaScript platform. Its purpose is to put modules in place so that node can find them, and manage dependency conflicts smartly.
Q.24 What is a string?
A string is actually a sequence of characters. In C++, it is a data type and a header file. This header file has powerful functions of string manipulation.
Q.25 What is a buffer?
A buffer is a temporary memory taken by a stream to hold some data until it is consumed. The buffer size is decided by the high Watermark property on the stream instance that is a number denoting the size of the buffer in bytes.
Q.26 Explain the use of Metadata API?
Well, metadata API is useful in deploying changes. We can retrieve, deploy, create, update, and delete customization information for organizations like Experience Cloud sites, custom object definitions, and page layouts. Hence, using Metadata API is ideal when the changes are complicated or when there is a need for a more rigorous change management process and an audit process for managing multiple workstreams.
Q.27 Define routing.
Routing is meant to define the way in which the client requests are handled by the application endpoints.
Q.28 What do you mean by debugging?
Debugging is basically the process of detecting and removing the existing and potential errors in a software code that may cause it to behave unexpectedly or even crash.
Q.29 Mention the different types of debugging.
Some debugging approaches are: Brute Force Method Program Slicing Cause Elimination Method Backtracking
Q.30 What are modules?
Modules are generally the blocks of encapsulated code used for communicating with an external application based on their related functionality.
Q.31 What is the HTTP module?
The HTTP module creates an HTTP server that listens to server ports and then gives back the response to the client. Moreover, we can create an HTTP server with the help of http. createServer() method.
Q.32 What are the uses of file system module?
Some common uses of the file system module: Read files Delete files Update files Create files Rename files
Q.33 What does MVC refer to?
The Model-View-Controller refers to an architectural pattern that separates an application into three major logical components, namely, the model, the view, and the controller.
Q.34 What is the use of MVC?
Well, the MVC enables the programmer to generate barriers for organizing the code allowing a programmer to compartmentalize functionality.
Q.35 Name the types of Node.js frameworks?
There are three different Node. js framework types. These are MVC, Full-Stack MVC, and REST API.
Q.36 What are middleware functions?
Middleware functions are the functions which have access to the request object, the response object, and the next function in the request-response cycle of the application.
Q.37 What is JSON?
The full form of JSON is JavaScript Object Notation. It is a file format useful for storing information in an organized and easy-to-access manner.
Q.38 What is MongoDB?
MongoDB is a source-available cross-platform document-oriented database program that is classified as a NoSQL database program. It uses JSON-like documents with optional schemas.
Q.39 What is the concept of error-first callback in NodeJS
The Node.js core API follow an pattern called error-first callback, in which a callback function is passed to the method with error object (error and data) is passed as first argument. If no error is encountered, then null is passed
Q.40 What is a template engine?
A template engine or template parser is a software designed for combining templates with a data model in order to produce result documents.
Q.41 Where does global dependencies are located under NodeJS
During installation, global dependencies are located in the local node_modules folder or as defined by NODE_PATH environment variable
Q.42 What do you know about Pug?
Pug is a kind of templating engine for Express and is used to remove the cluttering of server code with HTML, concatenating strings wildly to existing HTML templates.
Q.43 Which command in NodeJS, will list installed global libraries
The command is - npm list -g to see where global libraries are installed.
Q.44 Define EJS.
EJS is a templating language used to create HTML markup with plain JavaScript. Moreover, it helps to embed JavaScript to HTML pages.
Q.45 Which field value in package.json file under NodeJS, lists one or more executable files like to install into the PATH
bin, supply a bin field in your package.json which is a map of command name to local file name. On install, npm will symlink that file into prefix/bin for global installs, or ./node_modules/.bin/ for local installs.
Q.46 What is the use of a JSON web token?
A JSON web token is used for sending information that can be verified and trusted by means of a digital signature.
Get Govt. Certified Take Test