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 'npm run-script,' and how is it used?
'npm run-script' is used to execute custom scripts defined in the 'package.json' file, such as starting the server or running tests.
Q.4 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.5 What is the 'Event Loop' in Node.js?
The Event Loop is a core component of Node.js that handles asynchronous operations by managing the execution of callbacks in a non-blocking manner.
Q.6 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.7 What is a 'Promise' in Node.js?
A Promise is an object representing the eventual completion or failure of an asynchronous operation. It simplifies handling asynchronous code.
Q.8 Explain 'callback hell' in Node.js development.
'Callback hell,' also known as 'Pyramid of Doom,' occurs when nested callbacks make code difficult to read and maintain.
Q.9 What is 'async/await' in Node.js, and how does it work?
'async/await' is a syntax for handling asynchronous code in a more synchronous manner, making it easier to read and maintain.
Q.10 What are the core modules in Node.js?
Core modules are built-in modules provided by Node.js, such as 'fs,' 'http,' 'util,' 'path,' and 'os.'
Q.11 What is 'npm registry'?
The 'npm registry' is a public repository of Node.js packages where developers can publish, discover, and install packages.
Q.12 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.13 How can you handle multiple asynchronous operations in parallel in Node.js?
You can use 'Promise.all,' 'async/await,' or libraries like 'async' or 'bluebird' to handle multiple asynchronous operations concurrently.
Q.14 What is 'middleware' in Express.js?
Middleware functions in Express.js are functions that have access to the request and response objects and can be used to perform tasks between request and response handling.
Q.15 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.16 How do you serve static files using Express.js?
You can use the 'express.static' middleware to serve static files such as HTML, CSS, and images in an Express.js application.
Q.17 What is event loop in JavaScript?
Event loop, as the name suggests is loop which runs in background listening for various event emitters.
Q.18 Explain 'RESTful API' and its significance in Node.js.
A RESTful API is an architectural style for designing networked applications, emphasizing statelessness, scalability, and simplicity. It's commonly used in Node.js for building web services.
Q.19 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.20 What is 'Cross-Origin Resource Sharing (CORS)' in Express.js?
CORS is a security feature that allows or restricts web applications running at one origin to make requests for resources from another origin.
Q.21 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.22 What is 'body-parser' middleware in Express.js used for?
'body-parser' is used to parse incoming request bodies in different formats (e.g., JSON, URL-encoded) and make the data available in the 'req.body' object.
Q.23 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.24 How can you handle authentication in a Node.js application?
Authentication in Node.js can be handled using strategies like JWT (JSON Web Tokens), OAuth, or Passport.js for user authentication.
Q.25 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.26 What is 'WebSocket,' and how does it differ from HTTP?
WebSocket is a protocol that provides full-duplex communication channels over a single TCP connection, enabling real-time, bidirectional communication, unlike HTTP's request-response model.
Q.27 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.28 What is 'npm audit,' and why is it important?
'npm audit' is a command that checks a Node.js project's dependencies for known security vulnerabilities, helping developers ensure the security of their applications.
Q.29 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.30 How do you handle unhandled exceptions in Node.js?
You can use the 'process.on('uncaughtException', ...)' event listener to handle unhandled exceptions gracefully and prevent abrupt termination of the application.
Q.31 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.32 Explain the purpose of the 'cluster' module in Node.js.
The 'cluster' module is used to create multiple child processes (workers) of a Node.js application, taking advantage of multi-core CPUs for improved performance and concurrency.
Q.33 What is 'npm shrinkwrap,' and when should you use it?
'npm shrinkwrap' is used to lock down the versions of dependencies in a Node.js project to ensure consistent builds, especially in production environments.
Q.34 How do you manage environment variables in a Node.js application?
Environment variables can be managed using the 'process.env' object, 'dotenv' module, or through configuration management tools.
Q.35 What is 'WebSocket' and how is it different from 'Socket.io'?
WebSocket is a protocol for real-time, full-duplex communication, while 'Socket.io' is a library that provides WebSocket-like functionality with added features like fallback mechanisms and broadcasting.
Q.36 How does Node.js handle multiple concurrent connections?
Node.js uses an event-driven, non-blocking architecture to efficiently handle multiple concurrent connections without creating a separate thread for each connection.
Q.37 What is the 'child_process' module in Node.js, and when is it used?
The 'child_process' module is used for creating and managing child processes in Node.js, enabling the execution of external programs and scripts.
Q.38 Explain the 'os' module in Node.js.
The 'os' module provides information about the operating system, including CPU architecture, memory, and platform-specific functions.
Q.39 What is 'npm link,' and how is it used?
'npm link' is a command that allows you to create a symbolic link from a globally installed package to a local project, simplifying development and testing of packages.
Q.40 What are the differences between 'process.nextTick()' and 'setImmediate()' in Node.js?
'process.nextTick()' schedules a callback to execute before the next I/O cycle, while 'setImmediate()' schedules a callback to execute during the next iteration of the event loop.
Q.41 What is the 'pm2' module in Node.js, and how is it used?
'pm2' is a process manager for Node.js applications, used for managing and monitoring Node.js processes in production environments.
Q.42 How can you handle file uploads in an Express.js application?
File uploads in Express.js can be handled using middleware like 'multer' to process and save uploaded files.
Q.43 Explain the 'event-driven' nature of Node.js in detail.
Node.js is event-driven, meaning it uses an event loop to handle I/O operations and callbacks to manage asynchronous tasks, making it highly scalable and efficient.
Q.44 What is 'npm ci,' and how is it different from 'npm install'?
'npm ci' is a command used for installing dependencies in a more consistent and deterministic manner compared to 'npm install,' which may alter the 'package-lock.json' file.
Q.45 What is 'v8' in the context of Node.js?
'v8' refers to the JavaScript engine used by Node.js, developed by Google, which compiles and executes JavaScript code.
Q.46 How do you handle file system errors in Node.js?
File system errors can be handled using try-catch blocks or by using callback functions with error parameters.
Q.47 What are the advantages of using 'npm' for package management in Node.js?
'npm' offers a vast ecosystem of packages, easy installation and updating, dependency management, and a large community of contributors.
Q.48 Explain the concept of 'middleware' chaining in Express.js.
In Express.js, multiple middleware functions can be chained together, with each one being executed sequentially in the order they are defined, allowing for modular and organized request handling.
Q.49 What is 'npm audit fix,' and how does it work?
'npm audit fix' is a command used to automatically fix known vulnerabilities in project dependencies by updating them to patched versions.
Q.50 How can you use the 'util' module in Node.js?
The 'util' module provides utility functions for working with objects, errors, and asynchronous operations. It's often used for extending built-in objects and classes.
Q.51 What is the purpose of 'npm scripts' in a Node.js project?
'npm scripts' are defined in the 'package.json' file and allow you to define custom scripts for various tasks, such as running tests, building, or deploying the application.
Q.52 How do you implement session management in an Express.js application?
Session management in Express.js can be implemented using middleware like 'express-session' to store session data and manage user sessions.
Q.53 Explain the 'require.resolve' method in Node.js.
'require.resolve' is a method that returns the full path of a module or package that can be resolved by Node.js' module system without actually importing the module.
Q.54 How can you read command-line arguments in a Node.js application?
Command-line arguments can be accessed using the 'process.argv' array, or the 'yargs' or 'commander' libraries can be used for more advanced argument parsing.
Q.55 What is 'npm link,' and why would you use it?
'npm link' is a command used to create a symbolic link between a package in a local directory and a global package, making it easier to develop and test packages locally.
Q.56 Explain the 'dns' module in Node.js.
The 'dns' module in Node.js provides functions for working with DNS (Domain Name System) resolution and DNS-related operations.
Q.57 How can you handle routing in an Express.js application?
Routing in Express.js is handled using the 'express.Router' middleware, which allows you to define routes and associated request handlers.
Q.58 What is 'npm outdated,' and how is it used?
'npm outdated' is a command that checks for outdated package dependencies in a Node.js project, showing which packages have newer versions available.
Q.59 What are 'streams' in Node.js, and why are they important?
Streams are a fundamental concept in Node.js for reading and writing data efficiently, especially for large files and network communication. They help conserve memory and improve performance.
Q.60 How do you manage environment-specific configuration in a Node.js application?
Environment-specific configuration can be managed using environment variables or configuration files, allowing different settings for development, staging, and production environments.
Q.61 Explain the 'os' module in Node.js in more detail.
The 'os' module provides information about the operating system, including CPU information, memory usage, network interfaces, and more, making it useful for system-level tasks.
Q.62 What is 'npm prune,' and how is it used?
'npm prune' is a command used to remove unused dependencies from a Node.js project, helping to reduce the size of the 'node_modules' directory.
Q.63 How can you perform unit testing in a Node.js application?
Unit testing in Node.js can be done using testing frameworks like Mocha, Jest, or Jasmine, along with assertion libraries like Chai or 'assert.'
Q.64 What is 'npm audit' and why is it important for security?
'npm audit' is a command that checks a Node.js project's dependencies for known security vulnerabilities, helping developers identify and address security issues.
Q.65 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.66 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.67 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.68 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.69 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.70 What is Node.js?
Node.js is an open-source JavaScript runtime environment that allows running JavaScript code on the server-side.
Q.71 Name the three parts of DOM.
The three parts into which DOM is separated are: Core, HTML, and XML.
Q.72 What is the primary use of Node.js?
Node.js is primarily used for building scalable network applications and server-side applications.
Q.73 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.74 Explain the event-driven architecture in Node.js.
Node.js uses an event-driven, non-blocking I/O model, where actions are triggered by events and callbacks handle asynchronous operations.
Q.75 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.76 How can you create a simple HTTP server in Node.js?
You can create an HTTP server using the built-in http module in Node.js.
Q.77 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.78 What is the Node.js package manager, and what is its purpose?
The Node Package Manager (npm) is used for managing and installing packages and libraries for Node.js applications.
Q.79 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.80 What is the 'require' function in Node.js?
The 'require' function is used to import external modules or libraries in Node.js applications.
Q.81 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.82 What is the 'global' object in Node.js?
The 'global' object represents the global scope in Node.js, and its properties can be accessed from anywhere in the application.
Q.83 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.84 Explain callback functions in Node.js.
Callback functions are functions passed as arguments to other functions and are executed when a specific task is completed. They are commonly used for handling asynchronous operations.
Q.85 Define routing.
Routing is meant to define the way in which the client requests are handled by the application endpoints.
Q.86 What is 'npm init,' and how is it used?
'npm init' is a command used to initialize a Node.js project and create a 'package.json' file, which stores project metadata and dependencies.
Q.87 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.88 How can you include external modules in a Node.js application?
External modules can be included using the 'require' function and specifying the module name.
Q.89 Mention the different types of debugging.
Some debugging approaches are: Brute Force Method Program Slicing Cause Elimination Method Backtracking
Q.90 What is the purpose of the 'package.json' file in a Node.js project?
The 'package.json' file defines project metadata, dependencies, and scripts. It is crucial for managing project dependencies and configuration.
Q.91 What are modules?
Modules are generally the blocks of encapsulated code used for communicating with an external application based on their related functionality.
Q.92 What is the difference between 'npm install' and 'npm install --save'?
'npm install' installs a package locally, while 'npm install --save' installs a package and adds it as a dependency in the 'package.json' file.
Q.93 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.94 How do you handle errors in Node.js?
Errors in Node.js can be handled using try-catch blocks, callback error parameters, or by using error middleware.
Q.95 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.96 What is the purpose of the 'fs' module in Node.js?
The 'fs' module provides functions for working with the file system, such as reading, writing, and manipulating files.
Q.97 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.98 Explain the 'streams' module in Node.js.
The 'streams' module is used for handling data streams in Node.js, enabling efficient processing of data in chunks.
Q.99 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.100 What is the 'Buffer' class in Node.js?
The 'Buffer' class is used for handling binary data in Node.js, making it possible to work with binary streams and data.
Q.101 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.102 How do you create a simple web server using the 'http' module in Node.js?
You can create a web server by importing the 'http' module, creating a server object, and listening on a specific port for incoming HTTP requests.
Q.103 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.104 Explain the difference between 'console.log' and 'console.error' in Node.js.
'console.log' is used for regular log messages, while 'console.error' is used for error messages. Error messages often appear in red for better visibility.
Q.105 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.106 What is middleware in the context of Node.js and Express.js?
Middleware are functions that handle HTTP request/response operations in Express.js, allowing you to perform tasks like logging, authentication, and data processing.
Q.107 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.108 How do you install external packages using 'npm'?
You can install external packages using 'npm install ,' where '' is the name of the package you want to install.
Q.109 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.110 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.111 What is 'npm update,' and how is it used?
'npm update' is a command used to update packages to their latest versions.
Q.112 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.113 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.114 How can you handle asynchronous operations in Node.js?
Asynchronous operations can be handled using callback functions, promises, or async/await syntax to ensure non-blocking code execution.
Q.115 Which command in NodeJS, will list installed global libraries
The command is - npm list -g to see where global libraries are installed.
Q.116 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.117 Explain the 'exports' and 'module.exports' objects in Node.js.
'exports' is an object used to export functions and values from a module, while 'module.exports' is the actual object returned by 'require' when importing a module.
Q.118 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.119 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.
Q.120 What is the 'EventEmitter' class in Node.js, and how is it used?
The 'EventEmitter' class is used for implementing the observer pattern in Node.js, allowing objects to emit events and register listeners for those events.
Get Govt. Certified Take Test
 For Support