Node.js is a JavaScript runtime for server-side applications. It enables scalable and efficient web development with a vast ecosystem of packages.
Last updated on:- 15th June 2023
1.
What is Node.js ?
Node.js is an open-source JavaScript runtime environment that allows developers to run JavaScript code on the server-side. It is built on the V8 JavaScript engine and provides an event-driven, non-blocking I/O model for building scalable and high-performance applications.
2.
What is npm ?
npm (Node Package Manager) is the default package manager for Node.js. It provides a vast ecosystem of packages and libraries that can be easily installed, updated, and managed within Node.js projects.
3.
What is the difference between Node.js and JavaScript ?
Node.js is a runtime environment that allows JavaScript code to run on the server-side, while JavaScript is a programming language that can be run in web browsers or other environments. Node.js extends JavaScript by adding features and APIs specific to server-side development.
4.
What is the event-driven architecture in Node.js ?
The event-driven architecture in Node.js allows developers to write asynchronous code that responds to events. It utilizes callbacks, event emitters, and event loops to handle I/O operations efficiently and avoid blocking the execution of other code.
5.
What is a callback function in Node.js ?
A callback function in Node.js is a function that is passed as an argument to another function and is invoked once an asynchronous operation is completed. It allows developers to handle the result of the asynchronous operation or perform additional actions.
6.
What is the role of the 'require' function in Node.js ?
The 'require' function in Node.js is used to load and use external modules or libraries in a Node.js application. It allows you to include functionality from other files or packages into your application.
7.
What is the purpose of the 'exports' object in Node.js ?
The 'exports' object in Node.js is used to define and expose functionalities from a module. It allows you to specify which parts of the module should be accessible from other modules when the module is required using the 'require' function.
8.
What is a Promise in Node.js ?
A Promise in Node.js is an object that represents the eventual completion (or failure) of an asynchronous operation and its resulting value. It allows you to write asynchronous code in a more readable and manageable way, using methods like 'then' and 'catch'.
9.
What is middleware in Express.js ?
Middleware in Express.js is a function that sits between the server and the route handlers. It can perform tasks such as request parsing, authentication, logging, and error handling. Middleware functions can be used to modularize and enhance the functionality of Express.js applications.
10.
What is the difference between 'require' and 'import' in Node.js ?
'require' is the common way to include modules in Node.js, while 'import' is the ES6 syntax used for importing modules in JavaScript. 'import' requires additional configuration and is commonly used with transpilers like Babel when working with modern JavaScript features in Node.js.
11.
What is Express.js ?
Express.js is a popular web application framework for Node.js. It provides a simple and flexible set of features for building web applications, including routing, middleware support, template engines, and more.
12.
What is the purpose of the 'next' function in Express.js middleware ?
The 'next' function in Express.js middleware is used to pass control to the next middleware function in the chain. It is typically called at the end of a middleware function to indicate that it has completed its processing and to continue to the next middleware or route handler.
13.
What is the role of the 'module.exports' object in Node.js ?
The 'module.exports' object in Node.js is used to define the public interface of a module. It allows you to specify which parts of the module should be accessible when the module is required using the 'require' function.
14.
What is the difference between synchronous and asynchronous code in Node.js ?
Synchronous code in Node.js blocks the execution until a task is completed, while asynchronous code allows other tasks to continue while waiting for a task to complete. Asynchronous code in Node.js is commonly used for I/O operations to ensure optimal performance and responsiveness.
15.
What is the role of the 'buffer' class in Node.js ?
The 'buffer' class in Node.js is used to handle binary data. It provides methods for creating, manipulating, and reading binary data, such as encoding and decoding strings, working with streams, and performing low-level operations on buffers.
16.
What is the purpose of the 'fs' module in Node.js ?
The 'fs' module in Node.js provides an API for interacting with the file system. It allows you to read from and write to files, create or delete files and directories, modify file permissions, and perform other file-related operations.
17.
What is the event loop in Node.js ?
The event loop in Node.js is a mechanism that allows the execution of multiple asynchronous tasks in a non-blocking manner. It ensures that I/O operations and callbacks are processed efficiently and that the application remains responsive.
18.
What are streams in Node.js ?
Streams in Node.js provide an interface for reading from or writing to a continuous flow of data. They can be used to process large amounts of data efficiently, handle data in chunks, and perform operations like piping data between different streams.
19.
What is clustering in Node.js ?
Clustering in Node.js is a technique that allows you to utilize multiple processor cores to handle incoming requests. It creates child processes (workers) that share the same server port and distribute the workload, improving the application's performance and scalability.
20.
What is REPL in Node.js ?
REPL stands for Read-Eval-Print Loop. It is a built-in feature of Node.js that allows you to interactively execute JavaScript code and see the results immediately. The REPL environment provides a convenient way to experiment, debug, and learn Node.js.