[go: up one dir, main page]

0% found this document useful (0 votes)
8 views22 pages

IP Viva Questions

Uploaded by

chinuharyan12
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
8 views22 pages

IP Viva Questions

Uploaded by

chinuharyan12
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 22

What is HTML

HTML (HyperText Markup Language) is the standard language used to create and structure
content on the web. It provides the basic building blocks for web pages by defining the structure
of text, images, links, and other elements. HTML consists of a series of elements, or tags, that
define how different parts of the content should be displayed by a web browser.

HTML5 introduces new tags that improve the readability and structure of the code, such as
<header>, <footer>, <article>, <section>, and <nav>. These tags describe the
purpose of the content they enclose, making it more accessible to both humans and search
engines.

● HTML5 natively supports multimedia elements like audio and video without requiring
third-party plugins like Flash.
○ <audio>: For embedding sound files.
○ <video>: For embedding video files.
● These elements come with attributes to control playback, like controls, autoplay,
loop, and more.

HTML5 introduced new input types and form attributes to make forms more powerful and
user-friendly. Examples include:

● Input types: email, date, range, color, etc.


● Attributes like placeholder, autofocus, required, and pattern for validation.

What is DOM

Definition:

● The DOM is an API (Application Programming Interface) that browsers use to interpret
HTML and XML documents.
● It represents the page so that programming languages (e.g., JavaScript) can modify
its content, structure, and style.

Tree Structure:

● The DOM organizes the HTML document into a tree of nodes, where each node is an
object representing part of the document.
● The root of this tree is the document object, and from there, it branches into elements
such as <html>, <body>, <div>, <p>, etc.
● Each node can have parent-child relationships, with elements inside other elements
being children of their parent.
What is CSS

CSS (Cascading Style Sheets) is a stylesheet language used to describe the presentation (look
and formatting) of a web page written in HTML. It allows developers to separate the content of a
web page from its design, making it easier to maintain and update the visual appearance of the
website.
Styling: CSS is used to control the layout, colors, fonts, spacing, and overall visual presentation
of web pages.
Separation of Concerns: It separates the content (HTML) from the design, which promotes
cleaner code and reusability.
Selectors and Properties: CSS works by selecting HTML elements and applying styles
through properties (e.g., color, font-size, margin).
Cascading: The "Cascading" aspect means that styles are applied in a hierarchical order,
allowing inheritance and prioritization of styles.
Responsive Design: CSS allows for creating responsive designs using media queries to adjust
layouts for different screen sizes.

CSS Selectors

Types of CSS Selectors:

1. Universal Selector (*):


○ This selector targets all elements on the page.

* {
margin: 0;
padding: 0;
}

2. Type (Element) Selector:


○ This selector targets HTML elements by their tag name.

h1 {
color: blue;
}

3. Class Selector (.):


○ This selector targets elements based on the value of their class attribute. You
can apply the same class to multiple elements.
.button {

background-color: green;
}

ID Selector (#):

○ This selector targets a specific element with a unique id attribute. Since IDs
must be unique within a document, this selector applies styles to only one
element.

#header {
background-color: grey;
}

4. Attribute Selector:
○ Attribute selectors target elements based on the presence or value of their
attributes.

input[type="text"] {

border: 1px solid black;


}

5. Group Selector (``, ,):


○ This selector groups multiple selectors together, applying the same style to all
selected elements.
6. Descendant Selector (Space):
○ This selector targets elements that are nested inside another element
(descendants).
7. Child Selector (>):
○ This selector applies styles only to direct child elements of a specified parent.
8. Adjacent Sibling Selector (+):
○ This targets an element that is immediately preceded by a specified sibling.

General Sibling Selector (~):

○ This targets all siblings of an element that follow it.


9. Pseudo-Classes:
○ Pseudo-classes target elements based on their state or position in the DOM.
○ Common pseudo-classes include:
■ :hover: Applies styles when the user hovers over an element.
■ :focus: Applies styles when an element is focused (e.g., an input field).
■ :nth-child(): Targets elements based on their position in a parent.
10. Pseudo-Elements:
○ Pseudo-elements style specific parts of an element. Common pseudo-elements
are:
■ ::before and ::after: Insert content before or after the element's
content.
■ ::first-letter: Targets the first letter of an element.

What is JavaScript
JavaScript is a high-level, interpreted programming language primarily used for adding
interactivity and dynamic behavior to web pages. It is one of the core technologies of web
development, alongside HTML and CSS, and it runs directly in the browser without the need for
additional plugins.
JavaScript is frequently used to manipulate the DOM
JavaScript supports asynchronous operations using callbacks, promises, and async/await
Modern browsers come with powerful JavaScript engines (like Google’s V8 engine in Chrome)
that execute JavaScript code efficiently and allow for complex computations
Object-Oriented: JavaScript is an object-oriented language, supporting objects, prototyping,
and inheritance.
Weakly Typed: Variables in JavaScript don’t require a specific data type, making it a
dynamically typed language.
First-Class Functions: Functions in JavaScript are first-class citizens, meaning they can be
stored in variables, passed as arguments, and returned from other functions.
Lightweight and Interpreted: JavaScript is interpreted, meaning it's executed line-by-line by
the browser's JavaScript engine without needing a compiler.

Different ways to declare variables in JavaScript

In JavaScript, there are three main ways to declare variables: var, let, and const. Each has
different behaviors in terms of scope, hoisting, and reassignment, and it’s important to
understand their differences to write clean, efficient code.

1. var (Function-scoped declaration)

● Scope: Variables declared with var are function-scoped, meaning they are available
throughout the function in which they are declared. If declared outside any function, they
become global-scoped.
● Hoisting: var declarations are hoisted, meaning the variable is moved to the top of its
scope (function or global scope). However, only the declaration is hoisted, not the
initialization.
● Reassignment: Variables declared with var can be reassigned and re-declared within
the same scope

2. let (Block-scoped declaration)

● Scope: Variables declared with let are block-scoped, meaning they are only
accessible within the block of code (usually a {}) in which they are declared. This is
useful in for loops or if statements.
● Hoisting: let is hoisted but not initialized, meaning you cannot access the variable
before it is declared. Doing so will result in a ReferenceError.
● Reassignment: Variables declared with let can be reassigned, but they cannot be
re-declared in the same scope.

3. const (Block-scoped, constant declaration)

● Scope: Like let, variables declared with const are block-scoped, meaning they are
accessible only within the block in which they are defined.
● Hoisting: const is hoisted but not initialized, similar to let. You cannot access a
const variable before its declaration.
● Reassignment: const variables cannot be reassigned or re-declared. Once a value is
assigned to a const variable, it cannot be changed. However, if the const holds an
object or array, the contents of the object or array can be modified (but the reference
itself cannot be changed).

Different ways to declare functions in JavaScript

1. Function Declaration

A function declaration is the most common and straightforward way to define a function. It’s
hoisted, meaning the function can be called before it is declared in the code.

Syntax:
function functionName(parameters) {

// Function body

}
2. Function Expression

A function expression involves assigning a function to a variable. It


is not hoisted, meaning you can only call the function after it is
defined in the code.

Syntax:
const functionName = function(parameters) {

// Function body

};

3. Arrow Function (ES6)

An arrow function provides a shorter syntax for writing functions and behaves differently in
terms of handling the this keyword. It is also not hoisted.

Syntax:
const functionName = (parameters) => {

// Function body

Classes in JavaScript

In JavaScript, classes and inheritance are central concepts in object-oriented programming


(OOP). JavaScript has traditionally been a prototype-based language, but ES6 (ECMAScript
2015) introduced the class syntax, which makes it easier and more intuitive to implement OOP
principles, like inheritance and encapsulation

1. Classes in JavaScript

A class in JavaScript is a blueprint for creating objects. It encapsulates data and behavior
(methods) in a single construct. While JavaScript classes are syntactic sugar over its existing
prototype-based inheritance, they make the code cleaner and more understandable.

Declaring a Class

Classes are declared using the class keyword.

Syntax:
class ClassName {
constructor(parameters) {
// Initialization logic
}

// Method
methodName() {
// Method logic
}
}

2. Inheritance in JavaScript

Inheritance is a fundamental principle in object-oriented programming


where one class (child or subclass) inherits properties and methods
from another class (parent or superclass). This allows you to reuse
code and extend the functionality of existing classes.

Implementing Inheritance

In JavaScript, the extends keyword is used to create a subclass that


inherits from a superclass.

Syntax:
class ChildClass extends ParentClass {
constructor(parameters) {
super(parameters); // Calls the parent class constructor
// Additional properties or methods
}

// Overriding or new methods

3. Static Methods and Properties

Static methods and properties are defined on the class itself, rather
than on instances of the class. They are called directly on the class
and not on individual objects.
Syntax:
class MyClass {
static myStaticMethod() {
return 'This is a static method.';
}
}
console.log(MyClass.myStaticMethod());

Different Versions of JavaScript

ECMAScript 1 (ES1): Released in 1997, it standardized the core features of JavaScript,


defining syntax, types, and basic objects.
ECMAScript 2 (ES2): Introduced in 1998, it made minor refinements to the original specification
for alignment with international standards.
ECMAScript 3 (ES3): Launched in 1999, it added significant features like regular expressions,
error handling (try-catch), and enhanced array methods.
ECMAScript 4 (ES4): Proposed but abandoned due to its ambitious scope, which aimed to
introduce strong typing, classes, and modules.
ECMAScript 5 (ES5): Released in 2009, it brought major updates, including strict mode, JSON
support, and several new array and object methods.
ECMAScript 6 (ES6): Introduced in 2015, it was a major update with features like let and
const, arrow functions, classes, template literals, modules, and Promises.
ECMAScript 2016 (ES7): Added minimal changes, including
Array.prototype.includes() and the exponentiation operator.
ECMAScript 2017 (ES8): Introduced async/await for easier asynchronous programming, along
with new object and string methods.
ECMAScript 2018 (ES9): Enhanced the language with rest/spread properties, asynchronous
iteration, and new Promise methods.
ECMAScript 2019 (ES10): Brought new array methods like flat() and fromEntries(), as
well as optional catch binding.
ECMAScript 2020 (ES11): Added features like the nullish coalescing operator, optional
chaining, dynamic imports, and support for BigInt.
ECMAScript 2021 (ES12): Introduced logical assignment operators,
String.prototype.replaceAll(), and weak references.
ECMAScript 2022 (ES13): Included top-level await and support for public and private class
fields.
Explain Promises in JavaScript

A Promise is an object that represents the eventual completion (or failure) of an


asynchronous operation and its resulting value. Promises provide a cleaner alternative
to traditional callback-based approaches for handling asynchronous code, making it
easier to manage asynchronous operations and avoid callback hell.

Key Concepts of Promises

1. States:
○ A Promise can be in one of three states:
■ Pending: The initial state, indicating that the asynchronous
operation is ongoing.
■ Fulfilled: The state when the operation completes successfully,
resulting in a resolved value.
■ Rejected: The state when the operation fails, resulting in a reason
for the failure (an error).
2. Creating a Promise:
○ A Promise is created using the Promise constructor, which takes a
function called the executor. The executor function takes two parameters:
resolve and reject

const myPromise = new Promise((resolve, reject) => {


// Asynchronous operation
const success = true; // Simulate success or failure

if (success) {
resolve("Operation succeeded!");
} else {
reject("Operation failed!");
}
});

Consuming Promises:

● To handle the result of a Promise, you use the .then()


method for fulfilled promises and the .catch() method for
rejected promises.
myPromise
.then(result => {
console.log(result); // "Operation succeeded!"
})
.catch(error => {
console.error(error); // Handle the error
});

Chaining:

● Promises can be chained together, allowing you to perform a


series of asynchronous operations in a readable manner.

myPromise
.then(result => {
console.log(result);
return anotherAsyncOperation(); // Return another
promise
})
.then(nextResult => {
console.log(nextResult);
})
.catch(error => {
console.error(error);
});

Promise.all():

● This method allows you to run multiple promises concurrently and returns a
single Promise that resolves when all the promises in the iterable have resolved,
or rejects if any of the promises reject.

Promise.all([promise1, promise2])
.then(results => {
console.log(results); // Array of results from both promises
})
.catch(error => {
console.error(error); // Handle any error from the promises
});
What is Bootstrap

Bootstrap is a popular front-end framework designed for developing responsive and mobile-first
websites. It provides developers with a collection of pre-designed HTML, CSS, and JavaScript
components that can be used to build web applications quickly and efficiently. Here’s a detailed
overview:

Key Features of Bootstrap:

1. Responsive Design: Bootstrap uses a responsive grid system that adapts the layout to
different screen sizes, making it easy to create mobile-friendly websites.
2. Predefined Components: It offers a wide range of pre-built components, including:
○ Buttons: Styled buttons with various sizes and colors.
○ Navigation Bars: Responsive navigation menus that can be customized.
○ Forms: Form controls with validation and layout options.
○ Modals: Dialog boxes for alerts or forms.
○ Carousels: Image sliders for showcasing content.
3. Utility Classes: Bootstrap provides a variety of utility classes for common CSS
properties like spacing, text alignment, display properties, and more, making it easier to
apply styles without writing custom CSS.
4. JavaScript Plugins: Bootstrap includes JavaScript plugins that enhance interactivity,
such as tooltips, popovers, modals, and dropdowns, which are built on jQuery.
5. Customizable: Bootstrap can be customized easily through its source Sass files.
Developers can modify the variables to change the framework's appearance to better
suit their design.
6. Cross-Browser Compatibility: Bootstrap ensures that websites look consistent across
different browsers and devices.
7. Community Support: With a large community of users and contributors, Bootstrap
offers extensive documentation, tutorials, and third-party themes, making it easier for
developers to get started.

What is React

React is a popular JavaScript library developed by Facebook for building user interfaces,
particularly for single-page applications (SPAs). It enables developers to create fast, interactive,
and component-based web applications with a focus on the view layer of an application. Here’s
a detailed overview of React:
Key Features of React:

1. Component-Based Architecture:
○ React applications are built using components, which are reusable and
encapsulated pieces of code that manage their own state. This promotes better
organization and modularity in the codebase.
2. Declarative Syntax:
○ React uses a declarative approach to describe the UI. Instead of telling the
application how to change the UI based on the state, developers specify what the
UI should look like for a given state. React takes care of updating and rendering
the right components when the data changes.
3. Virtual DOM:
○ React uses a Virtual DOM, which is an in-memory representation of the real
DOM. When changes occur, React first updates the Virtual DOM, calculates the
differences, and then efficiently updates only the parts of the real DOM that have
changed. This leads to improved performance and smoother user experiences.
4. JSX (JavaScript XML):
○ React allows developers to write HTML-like syntax called JSX within JavaScript.
JSX provides a more intuitive way to create components and structure UI code,
making it easier to visualize the component hierarchy.
5. State Management:
○ Components in React can maintain their own local state, which allows them to
handle dynamic data. React also provides context and libraries like Redux or
MobX for managing application-wide state.
6. Unidirectional Data Flow:
○ React follows a unidirectional data flow, where data flows from parent
components to child components. This makes it easier to understand how data
changes over time and helps in debugging.
7. Ecosystem and Community:
○ React has a rich ecosystem of libraries, tools, and community support. Libraries
like React Router for routing and Axios for data fetching enhance its capabilities.
Additionally, there are numerous resources, tutorials, and third-party components
available.
8. Hooks:
○ Introduced in React 16.8, Hooks allow developers to use state and lifecycle
features in functional components, making it easier to manage state and side
effects without needing to write class components.
State

1. Definition:
○ State is a built-in object in React components that holds data that can change
over time. When the state of a component changes, React re-renders the
component to reflect the updated data.
2. Mutability:
○ State is mutable, meaning it can be changed or updated, typically through user
interactions, API calls, or other events.
3. Local to the Component:
○ State is local to the component that defines it. It can’t be directly accessed or
modified by other components unless passed down as props.
4. Managing State:
○ State is initialized in a class component using this.state or in a functional
component using the useState hook.
○ To update state, you use the setState method in class components or the
setter function returned by the useState hook in functional components.
5. Usage:
○ State is commonly used to manage data that changes over time, such as form
inputs, toggles, or data fetched from APIs.

Props

1. Definition:
○ Props (short for properties) are a mechanism for passing data and event
handlers from one component to another, typically from a parent component to a
child component.
2. Immutability:
○ Props are immutable; once they are passed to a component, the receiving
component cannot change them. This helps maintain a predictable data flow and
makes the component easier to debug.
3. Data Flow:
○ Props allow for a unidirectional data flow, meaning data flows from parent to child
components. This design helps in managing data and understanding how it
changes throughout the application.
4. Usage:
○ Props are used to configure components with external data, such as user
information, settings, or callback functions. They make components reusable and
customizable.
Different types of Components in React

1. Functional Components

● Definition: Functional components are simple JavaScript functions that return React
elements. They can accept props as arguments and are used primarily for rendering UI.
● Characteristics:
○ Stateless (until React Hooks are introduced).
○ Simpler and easier to read and test compared to class components.
○ Can use React Hooks to manage state and lifecycle methods.

2. Class Components

● Definition: Class components are ES6 classes that extend from React.Component.
They are more powerful than functional components as they can manage local state and
lifecycle methods.
● Characteristics:
○ Can hold and manage their own state using this.state.
○ Use lifecycle methods like componentDidMount, componentDidUpdate, and
componentWillUnmount to control the component's behavior at different points
in its life.

Explain Component life cycle in React

The component lifecycle in React refers to the series of events that occur from the creation of
a component to its unmounting. Understanding the lifecycle methods allows developers to
execute code at specific points in a component's life, enabling them to manage state, perform
side effects, and optimize performance. The lifecycle can be divided into three main phases:

1. Mounting

This phase occurs when a component is being created and inserted into the DOM.

● Methods:
○ constructor(): Initializes state and binds methods.
○ static getDerivedStateFromProps(): Updates state based on changes
in props (called before rendering).
○ render(): Describes what the UI should look like.
○ componentDidMount(): Invoked immediately after the component is mounted;
suitable for making API calls or initializing third-party libraries.
2. Updating

This phase happens when a component’s state or props change, causing it to re-render.

● Methods:
○ static getDerivedStateFromProps(): Same as in mounting; it can be
used during updates.
○ shouldComponentUpdate(): Determines whether the component should
re-render (used for performance optimization).
○ render(): Re-renders the component based on new state or props.
○ getSnapshotBeforeUpdate(): Captures some information (like scroll
position) from the DOM before it changes.
○ componentDidUpdate(): Invoked immediately after updating occurs; can be
used to perform operations based on changes (like fetching new data).

3. Unmounting

This phase occurs when a component is being removed from the DOM.

● Method:
○ componentWillUnmount(): Invoked immediately before a component is
unmounted; suitable for cleanup tasks like removing event listeners or canceling
network requests.

4. Error Handling

React components can also handle errors during rendering or lifecycle methods.

● Method:
○ static getDerivedStateFromError(): Updates state when an error is
caught during rendering.
○ componentDidCatch(): Invoked after an error is thrown; can be used for
logging error information.

Explain Hooks in React

Hooks

Hooks are functions that let you use state and other React features in functional components.
They were introduced in React 16.8 to enable functional components to have capabilities
previously available only in class components.
Explain Refs in React

Refs

Refs (short for references) provide a way to directly interact with DOM elements or React
components without causing re-renders. They are primarily used for accessing and
manipulating DOM nodes or integrating with third-party libraries.

Explain React Router

React Router

React Router is a standard library for routing in React that allows developers to create dynamic,
client-side routing in web applications. It helps manage navigation and rendering of different
components based on the URL.

Key Features of React Router:

1. Declarative Routing:
○ Routes are defined in a declarative manner, allowing developers to specify what
component should render based on the current URL.
2. Nested Routing:
○ React Router supports nested routes, enabling the creation of complex layouts
where routes can be nested within other routes.
3. Dynamic Routing:
○ It can handle dynamic routing, allowing routes to accept parameters from the
URL (e.g., user IDs, product IDs) and pass them to components.
4. Browser History:
○ React Router uses the browser's history API, enabling navigation without full
page reloads. This allows users to use the browser's back and forward buttons.
5. Route Matching:
○ It matches the current URL with the defined routes and renders the
corresponding components, ensuring a consistent user experience.

Core Components of React Router:

● BrowserRouter: The top-level component that enables routing for the entire application.
● Route: Defines a route and the component to render for a given path.
● Switch: Renders the first matching <Route> among its children, ensuring only one
route is displayed at a time.
● Link: Provides navigation to different routes without reloading the page.
Single Page Applications (SPAs)

A Single Page Application (SPA) is a web application that loads a single HTML page and
dynamically updates the content as the user interacts with the app, without requiring a full page
reload. SPAs provide a more fluid and responsive user experience.

Key Characteristics of SPAs:

1. Dynamic Content Loading:


○ SPAs load content dynamically using JavaScript, allowing for smoother
transitions and faster interactions.
2. Client-Side Routing:
○ Navigation within an SPA typically relies on client-side routing (e.g., using React
Router), enabling seamless transitions between different views or components
without reloading the entire page.
3. State Management:
○ SPAs often require efficient state management to keep track of application data.
This can be handled using libraries like Redux, MobX, or React Context API.
4. Improved User Experience:
○ By avoiding full page reloads, SPAs provide a more app-like experience, leading
to quicker interactions and reduced wait times.
5. Back and Forward Navigation:
○ SPAs handle browser history correctly, allowing users to navigate back and forth
between views, which is managed by the routing library.

Explain Node.js

Node.js is an open-source, cross-platform runtime environment that allows developers to


execute JavaScript code outside of a web browser. Built on the V8 JavaScript engine from
Google Chrome, Node.js enables server-side scripting, making it possible to build scalable
network applications.

Key Features of Node.js

1. Asynchronous and Event-Driven:


○ Node.js uses non-blocking I/O operations, allowing it to handle multiple requests
simultaneously without waiting for each operation to complete. This makes it
particularly suited for I/O-heavy tasks like web servers.
2. Single-Threaded:
○ Despite being single-threaded, Node.js uses an event loop to manage concurrent
operations, making it highly efficient in handling multiple connections.
3. NPM (Node Package Manager):
○ Node.js comes with NPM, which provides access to a vast ecosystem of libraries
and frameworks that can be easily installed and managed.
4. Cross-Platform:
○ Node.js applications can run on various operating systems (Windows, macOS,
Linux) without modification.
5. Full-Stack Development:
○ With Node.js, developers can use JavaScript for both client-side and server-side
development, enabling full-stack development using a single programming
language.

REPL in Node.js

REPL stands for Read-Eval-Print Loop, and it is an interactive programming environment that
allows developers to execute JavaScript code in real time. Node.js provides a built-in REPL,
which is useful for testing snippets of code, debugging, and experimenting with JavaScript.

Components of REPL

1. Read:
○ The REPL reads user input, which can be a single line or multiple lines of
JavaScript code.
2. Eval:
○ The input is evaluated (executed) as JavaScript code.
3. Print:
○ The result of the evaluated code is printed to the console.
4. Loop:
○ The process repeats, allowing for continuous input and output until the REPL is
exited.

Here are some of the most commonly used Node.js core modules:

1. HTTP

● Purpose: Enables the creation of HTTP servers and clients.


● Usage: It allows you to handle HTTP requests and responses.

2. File System (fs)

● Purpose: Provides an API to interact with the file system, allowing reading, writing, and
deleting files.
● Usage: Used for file operations, both asynchronously and synchronously.
3. Path

● Purpose: Provides utilities for working with file and directory paths.
● Usage: Helps to resolve and normalize paths, making them platform-independent.

4. Events

● Purpose: Implements the event-driven architecture in Node.js.


● Usage: Allows you to create and manage event emitters, facilitating asynchronous
programming.

5. URL

● Purpose: Provides utilities for URL resolution and parsing.


● Usage: Helps to work with URL strings, including parsing and formatting.

6. Crypto

● Purpose: Provides cryptographic functionality, including hashing and encryption.


● Usage: Used for secure data handling and verification.

7. Stream

● Purpose: Facilitates handling streaming data, such as reading from and writing to files,
HTTP requests, and more.
● Usage: Used for processing large amounts of data efficiently.

Streams
Streams are a way to handle reading and writing data in a continuous flow rather than in
chunks. They are particularly useful for processing large amounts of data efficiently without
loading everything into memory at once.

Types of Streams:

1. Readable Streams:
○ Used to read data from a source (e.g., files, HTTP requests).
○ They emit events like data, end, and error.
○ Example: fs.createReadStream() for reading files.
2. Writable Streams:
○ Used to write data to a destination (e.g., files, HTTP responses).
○ They provide methods like .write() and .end().
○ Example: fs.createWriteStream() for writing to files.
3. Duplex Streams:
○ Can read and write data simultaneously.
○ Example: Network sockets.
4. Transform Streams:
○ A type of duplex stream that can modify the data as it is read and written.
○ Example: zlib.createGzip() for compressing data.

Buffers

Buffers are temporary storage areas in memory that hold binary data. They are particularly
useful for working with streams, allowing you to read or write data in manageable chunks rather
than processing all the data at once.

Key Characteristics of Buffers:

● Fixed Size: Buffers have a predetermined size, which you define when creating them.
● Binary Data: They are designed to handle raw binary data, such as file contents or
network packets.
● Direct Memory Allocation: Buffers are allocated directly from the V8 engine's memory
pool, making them more efficient for certain operations.

What is Express

Express is a minimal and flexible web application framework for Node.js, designed for building
web applications and APIs. It simplifies the process of developing server-side applications by
providing a robust set of features and utilities for routing, middleware handling, and HTTP
request/response management. Express is widely used in the Node.js ecosystem and serves as
the foundation for many web applications and frameworks, including the popular full-stack
framework MEAN (MongoDB, Express, Angular, Node.js) and MERN (MongoDB, Express,
React, Node.js).

Key Features of Express

1. Middleware Support:
○ Express uses a middleware approach, allowing developers to define a sequence
of functions that can process requests and responses. Middleware can perform
actions such as logging, authentication, and request parsing.
2. Routing:
○ Express provides a powerful routing system that allows developers to define
routes for handling various HTTP methods (GET, POST, PUT, DELETE, etc.) and
endpoints. This makes it easy to structure APIs and web applications.
3. HTTP Utility Methods:
○ Express includes a variety of utility methods that simplify working with HTTP
requests and responses, such as setting response headers, redirecting, and
sending JSON data.
4. Template Engines:
○ Express supports various template engines (like EJS, Pug, Handlebars) for
rendering dynamic HTML pages on the server.
5. Static File Serving:
○ It can serve static files (e.g., images, CSS, JavaScript) easily, making it
straightforward to build front-end applications.
6. Robust Error Handling:
○ Express has built-in error handling capabilities, allowing developers to manage
errors gracefully and provide meaningful responses to clients.

What is REST API

A REST API (Representational State Transfer Application Programming Interface) is a set of


conventions and architectural principles for building web services that allow different systems to
communicate over the internet using standard HTTP methods. REST APIs are designed to be
simple, scalable, and stateless, making them a popular choice for web and mobile applications.

Key Principles of REST

1. Statelessness:
○ Each request from a client to the server must contain all the information needed
to understand and process the request. The server does not store any session
information about the client between requests, which simplifies scalability.
2. Client-Server Architecture:
○ REST APIs follow a client-server model where the client (frontend) and server
(backend) are separate. This separation allows for independent development,
deployment, and scaling of both components.
3. Resource-Based:
○ REST APIs are centered around resources, which are identified by unique URIs
(Uniform Resource Identifiers). Each resource can be manipulated using
standard HTTP methods (GET, POST, PUT, DELETE, etc.).
4. Use of Standard HTTP Methods:
○ RESTful services use standard HTTP methods to perform operations on
resources:
■ GET: Retrieve data from the server.
■ POST: Create a new resource.
■ PUT: Update an existing resource.
■ DELETE: Remove a resource.
5. Representation of Resources:
○ Resources can have multiple representations (e.g., JSON, XML). The client
specifies the desired representation using the Accept header, and the server
responds accordingly.
6. Stateless Communication:
○ Each request from the client to the server must include all necessary information,
allowing the server to process requests independently without retaining client
state.
7. Hypermedia as the Engine of Application State (HATEOAS):
○ While not always implemented, RESTful APIs can provide hypermedia links in
responses, allowing clients to navigate the API dynamically based on the current
state.

Advantages of REST APIs

● Simplicity: REST APIs are easy to understand and use, making them accessible for
developers.
● Scalability: Statelessness allows REST APIs to handle a large number of requests
efficiently.
● Flexibility: Clients can choose the format they want to receive data in (JSON, XML,
etc.), making it easier to integrate with various systems.
● Interoperability: REST APIs can be consumed by any client that understands HTTP,
regardless of the programming language or platform.

You might also like