20250501111652-Module-3 Notes With Frontsheet
20250501111652-Module-3 Notes With Frontsheet
Study Material
Course Name: Full Stack Development
By
Chapter 1,2,3
Introduction to MERN:
MERN components,
Server less Hello world.
React Components:
Issue Tracker,
React Classes,
Composing Components,
Passing Data Using Properties,
Passing Data Using Children,
Dynamic Composition.
SJB Institute of Technology, Bangalore – 60
BACHELOR OF ENGINEERING
DEPARTMENT OF INFORMATION SCIENCE & ENGINEERING
Introduction to MERN
MERN is a full-stack JavaScript solution for developing web applications, meaning both the client-side
(React) and server-side (Node.js, Express) are written in JavaScript, simplifying the development process.
The rise of MERN is linked to the trend of building Single Page Applications (SPAs), where data is
dynamically loaded without reloading the entire page. React is a key part of this as it allows for dynamic
updates to the user interface. MongoDB and Express work together to handle data and server-side logic.
The MERN stack is a popular collection of technologies used to build modern web applications.
MERN stands for:
1. MongoDB: A NoSQL database that stores data in a flexible, JSON-like format, making it ideal for
applications that require scalable and flexible data storage.
2. Express.js: A minimal and flexible Node.js web application framework that simplifies server-side
development by providing essential features like routing and middleware to handle HTTP requests.
3. React: A JavaScript library for building user interfaces. Unlike full-fledged frameworks like Angular,
React focuses on the "view" part of the MVC (Model-View-Controller) architecture. It allows developers
to create interactive and dynamic user interfaces by breaking them down into reusable components.
4. Node.js: A JavaScript runtime built on Chrome’s V8 JavaScript engine. It allows developers to run
JavaScript on the server-side, enabling full-stack JavaScript development (both client and server-side).
MERN Components
The MERN stack consists of four core components that work together to create modern web applications.
Here are the key components in detail:
1. MongoDB (Database)
• Type: NoSQL database.
• Role: Stores data in flexible, JSON-like documents (BSON format).
• Why MongoDB?
o It's scalable, fast, and schema-less, allowing dynamic data models.
SJB Institute of Technology, Bangalore – 60
BACHELOR OF ENGINEERING
DEPARTMENT OF INFORMATION SCIENCE & ENGINEERING
React Component
MongoDB
MongoDB is a NoSQL database used in the MERN stack (MongoDB, Express.js, React.js, Node.js). It
stores data as documents (JSON-like objects) instead of using tables and rows like relational databases
(MySQL, PostgreSQL).
• A NoSQL document-oriented database that stores data in JSON-like BSON (Binary JSON)
format.
• Unlike SQL databases, MongoDB doesn’t enforce a fixed schema, making it flexible for storing
different types of data.
• Supports horizontal scaling and replication, meaning it can distribute data across multiple servers
for better performance.
1. NoSQL Database
• NoSQL = Non-Relational → No tables, rows, or foreign keys
2. Document-Oriented Storage
• Instead of tables and rows, MongoDB uses collections and documents.
3. Schema-Less Database
• No predefined schema → You can add fields dynamically.
• Great for rapid development (no need for migrations).
4. JavaScript-Based Query Language
• Unlike SQL (which uses SELECT, WHERE, etc.), MongoDB queries are written in JSON-like
syntax.
• Built-in support for JavaScript → Works well with Node.js.
• Why BSON?
More efficient storage
Supports additional data types (e.g., date, binary)
Faster querying
• Relational databases ensure strong consistency (always up-to-date data), but MongoDB prioritizes
availability and partition tolerance (CAP theorem).
• Trade-off: MongoDB allows eventual consistency (data may not be instantly updated everywhere).
SJB Institute of Technology, Bangalore – 60
BACHELOR OF ENGINEERING
DEPARTMENT OF INFORMATION SCIENCE & ENGINEERING
Nodejs
Expressjs
Express.js is a framework for Node.js that makes it easy to build web servers and APIs. Node.js alone is just
a runtime environment; writing a server from scratch in Node.js is complex. Express simplifies web server
development by handling routing, middleware, and HTTP request/response management.
1. Easy to set up – Requires minimal code to create a server.
2. Powerful routing system – Handles different HTTP methods (GET, POST, etc.).
3. Supports middleware – Allows modular and reusable code.
4. Works well with APIs – Ideal for RESTful services and Single Page Applications (SPAs).
5. Scalable – Used in production by companies like Uber, PayPal, and Twitter.
• Solution: React-Router enables client-side routing, meaning users can navigate between pages
without full-page reloads.
• How It Works:
o Similar to Express.js routing but for the frontend.
o Updates the URL and loads the correct React component without refreshing the page.
o Manages the browser’s Back button functionality.
2. React-Bootstrap (UI Framework for React)
• Problem: Styling and UI components are time-consuming to build from scratch.
• Solution: Webpack bundles multiple files into a single optimized file for the browser.
• Key Features:
o Converts JSX, ES6+ code into browser-friendly JavaScript.
o Supports CSS, images, fonts processing.
o Allows lazy loading for better performance.
4. ESLint (Code Linter for JavaScript/React)
• Ensures consistent coding style and catches errors early.
ESLint is a widely used static code analysis tool (linter) for JavaScript and React applications. It helps
developers identify and fix code errors, enforce coding standards, and improve overall code quality. By
analyzing JavaScript and JSX code, ESLint detects issues such as syntax errors, undefined variables,
unused imports, and inconsistent formatting.
SJB Institute of Technology, Bangalore – 60
BACHELOR OF ENGINEERING
DEPARTMENT OF INFORMATION SCIENCE & ENGINEERING
5. Bootstrap
Bootstrap is a popular CSS framework that helps developers create responsive and visually appealing
websites quickly. It provides a collection of pre-designed components such as buttons, forms, modals, and
navigation bars, which can be easily customized. Bootstrap also includes a responsive grid system that uses
Flexbox and CSS Grid to ensure layouts adjust properly on different screen sizes. Additionally, it comes
with built-in JavaScript components like carousels and tooltips. It is widely used for front-end development
to simplify UI design without writing extensive custom CSS.
6. Babel
Babel is a JavaScript compiler that allows developers to write modern JavaScript (ES6 and beyond) while
ensuring compatibility with older browsers. Since not all browsers support the latest JavaScript features,
Babel converts newer syntax—such as arrow functions, async/await, and classes—into older ES5
JavaScript that can run everywhere. It is commonly used in conjunction with tools like Webpack and React,
where JSX and modern JavaScript features are frequently used. By using Babel, developers can write
cleaner, future-proof code without worrying about browser limitations.
SJB Institute of Technology, Bangalore – 60
BACHELOR OF ENGINEERING
DEPARTMENT OF INFORMATION SCIENCE & ENGINEERING
You can test this file by opening it in a browser. It may take a few seconds to load the React libraries, but
soon enough, you should see the browser displaying the caption, as seen in Figure 2-1. You should also be
able to hover over the text or anywhere to its right side within the boundaries of the outer div, and you
should be able to see the tooltip “Outer div” pop up.
SJB Institute of Technology, Bangalore – 60
BACHELOR OF ENGINEERING
DEPARTMENT OF INFORMATION SCIENCE & ENGINEERING
Project Set-Up
This section explains how to properly set up a React project for development and production, moving beyond the
simple server-less approach used for initial learning.
Why Move Beyond Server-Less Setup?
1. Performance Issues in Development
o Using CDNs to load scripts introduces additional time.
o Babel compiler, which converts JSX to JavaScript, is large and can slow down loading times.
2. Performance Issues in Production
o Runtime compilation of JSX (done in the browser) affects page load speed.
o For large-scale applications, this reduces user experience.
Solution:
Setting up a proper project with Node.js and an HTTP server.
SJB Institute of Technology, Bangalore – 60
BACHELOR OF ENGINEERING
DEPARTMENT OF INFORMATION SCIENCE & ENGINEERING
Step 1:
Installing nvm (Node Version Manager)
Windows: Use nvm-windows or install Node.js directly. After installing nvm, restart your shell/terminal.
Step 2:
Installing Node.js using nvm
nvm install 10(long term support)
Check the node version - node --version
Check the npm version - npm --version
Step 3:
Setting Up a React Project
1. Create a new project folder:
mkdir pro-mern-stack-2
cd pro-mern-stack-2
2. Initialize a new npm project: npm init
Step 4:
Installing Express (HTTP Server) - Install Express framework to serve React files:
npm install express
Express
Express is a lightweight framework for building web servers in Node.js.Initially, the focus is on serving
static files (like index.html) to understand how Express works without deep server-side coding.
This explanation provides an introduction to Express.js, a web framework for Node.js. It walks through
setting up an Express server to serve static files and explains important concepts related to Express.
1. Installing Express
• Express needs to be installed using:
app.use(express.static('public'));
• This middleware:
app.listen(3000, function () {
console.log('App started on port 3000');
});
• Running the server:
node server.js
• This will start a web server, accessible at http://localhost:3000/.
"scripts": {
"start": "node server/server.js"
}
• Now, just running:
npm start
will start the server.
SJB Institute of Technology, Bangalore – 60
BACHELOR OF ENGINEERING
DEPARTMENT OF INFORMATION SCIENCE & ENGINEERING
Since we moved JSX out of index.html, we need to create a new file App.jsx inside the public directory:
App.jsx
const element = (
<div title="Outer div">
<h1>Hello World!</h1>
</div>
);
ReactDOM.render(element, document.getElementById('contents'));
• This contains only the JSX code, without the <script> tag.
SJB Institute of Technology, Bangalore – 60
BACHELOR OF ENGINEERING
DEPARTMENT OF INFORMATION SCIENCE & ENGINEERING
JSX Transform
JSX (JavaScript XML) is a syntax extension used in React that allows us to write HTML-like code inside
JavaScript files. However, browsers do not understand JSX natively. This is where Babel comes in—it
transforms JSX into standard JavaScript that browsers can execute.
Updating index.html
SJB Institute of Technology, Bangalore – 60
BACHELOR OF ENGINEERING
DEPARTMENT OF INFORMATION SCIENCE & ENGINEERING
• The Babel runtime script (used for on-the-fly JSX transformation in the browser) is no longer
needed.
Changes in index.html
Before:
<script src="https://unpkg.com/@babel/standalone@7/babel.min.js"></script>
<script src="/App.jsx" type="text/babel"></script>
After:
<script src="/App.js"></script>
SJB Institute of Technology, Bangalore – 60
BACHELOR OF ENGINEERING
DEPARTMENT OF INFORMATION SCIENCE & ENGINEERING
Issue Tracker
Issue Tracker
These applications help you create a bunch of issues or bugs, assign them to people, and track their statuses.
These are essentially CRUD applications (Create, Read, Update, and Delete a record in a database) that
manage a list of objects or entities. The CRUD pattern is so useful because pretty much all enterprise
applications are built around the CRUD pattern on different entities or objects. In the case of the Issue
Tracker, we’ll only deal with a single object or record, because that’s good enough to depict the pattern.
An issue should have following attributes:
• A title that summarizes the issue (freeform long text)
• An owner to whom the issue is assigned (freeform short text)
• A status indicator (a list of possible status values)
• Creation date (a date, automatically assigned)
• Effort required to address the issue (number of days, a number)
• Estimated completion date or due date (a date, optional)
React Class
React class component is a javascript class that extends React.Component,which is the base class provided
by the react library. It must include a render() method. This method tells react what to display on the screen
and must return a react element(e.g., a JSX element like <div>).
React Classes are a way to create reusable and powerful UI components.
Before React Hooks (introduced in React 16.8), class components were the standard way to:
• Manage state
• Handle lifecycle events (e.g., when the component is mounted, updated, etc.)
• Respond to user interactions
Now, both Class Components and Function Components can be used, but this chapter focuses on the
traditional Class Component style.
A React Class Component is built by extending React.Component. It must have at least a render() method.
• HelloWorld is a class.
• It extends React.Component, which means it inherits everything React needs to render it.
• The render() function tells React what UI to show on the screen.
SJB Institute of Technology, Bangalore – 60
BACHELOR OF ENGINEERING
DEPARTMENT OF INFORMATION SCIENCE & ENGINEERING
• Array.from() is used to create an array of greetings: ["Hello Africa!", "Hello America!", ...]
• join(' ') merges them into a single string
• JSX is returned with that message inside an <h1>
Term Meaning
HelloWorld The component class you defined
<HelloWorld /> An instance of that component (like using <div> in HTML)
div, h1 Built-in React components
render() The method React calls to show UI
React.Component The base class every custom class must extend
Element The object representation of <HelloWorld /> passed to ReactDOM
SJB Institute of Technology, Bangalore – 60
BACHELOR OF ENGINEERING
DEPARTMENT OF INFORMATION SCIENCE & ENGINEERING
Composing Component
• Larger components should be split into fine-grained components when there is a logical separation
possible between the fine-grained components. In this section we’ll create logically separated components.
• When there is an opportunity for reuse, components can be built which take in different inputs from
different callers.
• React’s philosophy prefers component composition in preference to inheritance. For example, a
specialization of an existing component can be done by passing properties to the generic component rather
than inheriting from it.
• In general, remember to keep coupling between components to a minimum (coupling is where one
component needs to know about the details of another component, including parameters or properties
passed between them).
SJB Institute of Technology, Bangalore – 60
BACHELOR OF ENGINEERING
DEPARTMENT OF INFORMATION SCIENCE & ENGINEERING
Dynamic Composition
Instead of manually writing multiple <IssueRow> components, React allows us to dynamically generate
these rows from a JavaScript array. This is useful when:
• You have a list of items (like issues).
• You want to loop through them and render components for each item.
SJB Institute of Technology, Bangalore – 60
BACHELOR OF ENGINEERING
DEPARTMENT OF INFORMATION SCIENCE & ENGINEERING
SJB Institute of Technology, Bangalore – 60
BACHELOR OF ENGINEERING
DEPARTMENT OF INFORMATION SCIENCE & ENGINEERING
The browser displays a full issue tracker table, dynamically generated from the array — with columns for all issue
fields, formatted neatly and flexibly styled via CSS.
Prepared By,
Prof. Ranjitha J,
Dept, of ISE
SJB Institute of Technology