FSD Unit 1
FSD Unit 1
T D SAI KISHORE
Assistant Professor
Department
of
Mechanical Engineering
1
Full Stack Development (MERN)-CS631PE Department of CSE
Syllabus
UNIT-I Introduction to Full Stack Development: Understanding the Basic Web Development
Framework- User, Browser, Webserver, Backend Services, Full Stack Components - Node.js, MongoDB,
Express, React, Angular. Java Script Fundamentals, NodeJS- Understanding Node.js, Installing Node.js,
Working with Node Packages, creating a Node.js Application, Understanding the Node.js Event Model,
Adding Work to the Event Queue, Implementing Callbacks.
UNIT-II Node.js:
Working with JSON, Using the Buffer Module to Buffer Data, Using the Stream Module to Stream Data,
Accessing the File System from Node.js- Opening, Closing, Writing, Reading Files and other File System
Tasks. Implementing HTTP Services in Node.js- Processing URLs, Processing Query Strings and Form
Parameters, Understanding Request, Response, and Server Objects, Implementing HTTP Clients and
Servers in Node.js, Implementing HTTPS Servers and Clients. Using Additional Node.js Modules-Using
the OS Module, Using the util Module, Using the DNS Module, Using the crypto Module.
UNIT-III MongoDB:
Need of NoSQL, Understanding MongoDB, MongoDB Data Types, Planning Your Data Model, Building
the MongoDB Environment, Administering User Accounts, Configuring Access Control, Administering
Databases, Managing Collections, Adding the MongoDB Driver to Node.js, Connecting to MongoDB
from Node.js, Understanding the Objects Used in the MongoDB Node.js Driver, Accessing and
Manipulating Databases, Accessing and Manipulating Collections
UNIT-V React:
Need of React, Simple React Structure, The Virtual DOM, React Components, Introducing React
Components, Creating Components in React, Data and Data Flow in React, Rendering and Life Cycle
Methods in React, working with forms in React, integrating third party libraries, Routing in React
2
Full Stack Development (MERN)-CS631PE Department of CSE
UNIT-1
Understanding the Basic Web Development Framework
Web development frameworks provide a structured approach to building web applications, making
development faster, more efficient, and scalable. These frameworks handle routine tasks such as
routing, authentication, and database interaction, allowing developers to focus on business logic.
1. What is a Web Development Framework?
A web development framework is a collection of libraries, tools, and best practices that simplify the
development of web applications. It provides a foundation that developers can build upon instead of
coding everything from scratch.
Types of Web Development Frameworks
1. Front-end Frameworks – Used for UI development (e.g., React.js, Angular, Vue.js).
2. Back-end Frameworks – Used for server-side logic (e.g., Express.js, Spring Boot, Django).
3. Full-stack Frameworks – Include both front-end and back-end capabilities (e.g., Next.js,
Meteor).
2. Front-End Frameworks
Front-end frameworks help developers create interactive and responsive user interfaces.
Common Front-End Frameworks
Framework Language Features
React.js JavaScript Component-based, Virtual DOM, Hooks
Angular TypeScript MVC, Two-way Data Binding, Dependency Injection
Vue.js JavaScript Reactive Data Binding, Component-based
Core Concepts in Front-End Development
• HTML (Hypertext Markup Language) – Structure of a web page.
• CSS (Cascading Style Sheets) – Styling and layout.
• JavaScript (JS) – Interactivity and dynamic behaviour.
Tools for Front-End Development
• Webpack, Babel – Bundling and transfilling code.
• Tailwind CSS, Bootstrap – Pre-built styling frameworks.
• React Router – Handles navigation in React applications.
3. Back-End Frameworks
Back-end frameworks manage server-side logic, database interactions, and authentication.
3
Full Stack Development (MERN)-CS631PE Department of CSE
4
Full Stack Development (MERN)-CS631PE Department of CSE
Detailed Explanation of Full-Stack Components (Node.js, MongoDB, Express, React, Angular) &
JavaScript Fundamentals
Full-stack development refers to the combination of both front-end and back-end technologies to build
a complete web application. This guide will cover essential full-stack components, including Node.js,
MongoDB, Express.js, React, Angular, and JavaScript fundamentals.
1. JavaScript Fundamentals
JavaScript is the core programming language used for full-stack development. Understanding its
fundamentals is essential before diving into frameworks like Node.js, React, Angular, and Express.
Key JavaScript Concepts
Concept Explanation
Variables Use var, let, and const to declare variables.
JavaScript has primitive types (string, number, boolean, null, undefined)
Data Types
and objects.
Define functions using function declarations, expressions, and arrow
Functions
functions (()=>{}).
Includes let/const, template literals, spread/rest operators,
ES6 Features
destructuring, promises, and async/await.
Methods like document.getElementById(), event listeners to
DOM Manipulation
manipulate HTML elements.
Event Handling Handling user interactions using addEventListener().
Uses callbacks, Promises, and async/await for handling async
Asynchronous JS
operations.
Closures & Scope Understanding block scope, function scope.
Object-Oriented
JavaScript supports prototype-based inheritance and ES6 class syntax.
Programming (OOP)
Modules Use import and export to organize code in ES6.
Error Handling Using try...catch for exception handling.
2. Data Types
JavaScript has primitive types (string, number, boolean, null, undefined) and objects.
let str = "Hello"; // String
let num = 42; // Number
let isTrue = true; // Boolean
let empty = null; // Null
let notDefined; // Undefined
let obj = { key: "value" }; // Object
3. Functions
Define functions using function declarations, expressions, and arrow functions.
function regularFunction() { return "Hello"; } // Function declaration
const functionExpression = function () { return "Hello"; }; // Function expression
5
Full Stack Development (MERN)-CS631PE Department of CSE
4. ES6 Features
Modern JavaScript features.
let name = "John";
console.log(`Hello, ${name}!`); // Template literals
let arr = [1, 2, 3];
let newArr = [...arr, 4]; // Spread operator
const person = { firstName: "John", lastName: "Doe" };
const { firstName, lastName } = person; // Object destructuring
const fetchData = async () => {
let data = await fetch("https://api.example.com");
return data.json();
}; // Async/Await
5. DOM Manipulation
Modify HTML elements dynamically.
document.getElementById("demo").innerText = "Hello, World!";
document.querySelector(".my-class").style.color = "red";
6. Event Handling
Handle user interactions.
document.getElementById("btn").addEventListener("click", () => {
alert("Button Clicked!");
});
7. Asynchronous JS
Use callbacks, Promises, and async/await.
setTimeout(() => console.log("Executed after 2 seconds"), 2000); // Callback
fetch("https://api.example.com")
.then(response => response.json()) // Promise
.then(data => console.log(data))
.catch(error => console.error(error));
6
Full Stack Development (MERN)-CS631PE Department of CSE
console.log(count);
};
}
const counter = outer();
counter(); // 1
counter(); // 2
10. Modules
Organize code using import and export.
// module.js
export const greet = () => console.log("Hello!");
// main.js
import { greet } from "./module.js";
greet();
2. Node.js
Node.js is a runtime environment that allows JavaScript to run on the server-side. It is built on the V8
engine (same engine used in Chrome).
Why Use Node.js?
• Non-blocking, event-driven architecture
• Uses JavaScript for both front-end and back-end
• Fast execution speed due to the V8 engine
• Large ecosystem with NPM packages
Core Features of Node.js
7
Full Stack Development (MERN)-CS631PE Department of CSE
Feature Explanation
Single-threaded Event
Handles multiple requests asynchronously using an event-driven model.
Loop
Modules Built-in modules (fs, http, path), and third-party modules via npm.
Express.js A lightweight framework to build APIs and web applications.
File System Access Read and write files using the fs module.
Streams Handles large files efficiently.
Web Sockets Real-time communication using socket.io.
3. Express.js
Express.js is a lightweight Node.js framework for building web applications and APIs.
Why Use Express?
• Simplifies routing and request handling
• Middleware support for logging, authentication, and more
• Supports RESTful APIs
Core Features of Express.js
Feature Explanation
Routing Define application endpoints (app.get(), app.post()).
Middleware Functions that process requests (e.g., authentication, logging).
Template Engines Use EJS, Handlebars, or Pug for rendering views.
Static File Serving Serve static files like CSS and images.
Example: Simple Express.js Server
const express = require('express');
const app = express();
app.listen(3000, () => {
console.log('Server running on port 3000');
});
4. MongoDB
MongoDB is a NoSQL database that stores data in JSON-like documents.
Why Use MongoDB?
8
Full Stack Development (MERN)-CS631PE Department of CSE
5. React.js
React.js is a popular JavaScript library for building UI components.
Why Use React?
• Component-based architecture
• Virtual DOM for efficient rendering
• Supports hooks and functional components
function App () {
return <h1>Hello, React! </h1>;
}
export default App;
6. Angular
Angular is a TypeScript-based framework for building web applications.
Why Use Angular?
• Built-in support for MVC architecture
• Two-way data binding
• Dependency Injection
9
Full Stack Development (MERN)-CS631PE Department of CSE
@Component({
selector: 'app-root',
template: `<h1>Hello, Angular!</h1>`
})
export class AppComponent {}
Install Node.js
Step 1: Download Node.js
1. Go to the official Node.js website.
2. You will see two versions:
o LTS (Long Term Support): Recommended for most users and production
environments.
o Current: The latest features, but may not be as stable.
3. Click on the appropriate version for your operating system (Windows, macOS, or Linux).
10
Full Stack Development (MERN)-CS631PE Department of CSE
3. Installing Packages
A. Installing a Package Globally
Some tools (like nodemon) are installed globally to be used system-wide:
npm install -g nodemon
You can now use nodemon from the terminal.
B. Installing a Package Locally
To install a package only for a specific project (e.g., express):
npm install express
This adds express to node_modules and updates package.json.
C. Installing Dev Dependencies
11
Full Stack Development (MERN)-CS631PE Department of CSE
For packages needed only during development (e.g., testing tools like jest):
npm install --save-dev jest
These are saved under devDependencies in package.json.
4. Using Installed Packages
After installing express, create a file (server.js) and use it:
const express = require('express');
const app = express();
5. Managing Packages
A. Checking Installed Packages
List installed dependencies:
npm list
List globally installed packages:
npm list -g --depth=0
B. Updating Packages
To update all dependencies to the latest compatible versions:
npm update
To update a specific package:
npm update express
C. Removing a Package
Uninstall a package:
npm uninstall express
If removing a dev dependency:
npm uninstall jest --save-dev
7. Running Scripts
Define scripts inside package.json:
"scripts": {
"start": "node server.js",
"dev": "nodemon server.js"
}
12
Full Stack Development (MERN)-CS631PE Department of CSE
console.log('Start');
setTimeout(() => {
console.log('Task added to Event Queue');
}, 2000);
console.log('End');
Execution Flow:
1. Start is printed.
13
Full Stack Development (MERN)-CS631PE Department of CSE
3. Implementing Callbacks
A callback is a function that is passed as an argument to another function and is executed when an
asynchronous operation completes.
Example: Callback in File Reading
const fs = require('fs');
console.log('Start');
console.log('End');
Execution Flow:
1. Start is printed.
2. fs.readFile() starts reading the file but doesn’t block execution.
3. End is printed immediately.
4. Once the file read completes, the callback executes and prints File Content.
Output:
Start
End
File Content: <content of file.txt>
The Event Loop is the core of Node.js’s asynchronous behavior. It continuously checks the Event Queue
for pending tasks and executes them.
Event Loop Phases:
1. Timers → Executes setTimeout() and setInterval() callbacks.
2. I/O Callbacks → Executes callbacks from completed I/O operations (like fs.readFile()).
3. Idle & Prepare → Internal processing.
4. Poll → Fetches new I/O events, waiting for new tasks.
5. Check → Executes setImmediate() callbacks.
6. Close Callbacks → Executes close event callbacks (like socket.on('close')).
14
Full Stack Development (MERN)-CS631PE Department of CSE
process.nextTick(() => {
console.log('Next Tick Callback');
});
console.log('End');
Output:
Start
End
Next Tick Callback
process.nextTick() ensures the callback runs before any I/O operations or setTimeout().
console.log('End');
Output: (Order may vary)
Start
End
setImmediate Callback
setTimeout Callback
Why?
• setImmediate(): executes after the poll phase.
• setTimeout(0): executes after a minimal delay but still waits for the poll phase to clear.
emitter.emit('greet', 'Alice');
Output:
Hello, Alice!
Example: Handling Multiple Event Listeners
emitter.on('data', (msg) => console.log(`Listener 1: ${msg}`));
emitter.on('data', (msg) => console.log(`Listener 2: ${msg}`));
15
Full Stack Development (MERN)-CS631PE Department of CSE
readFiles();
Advantages of Promises:
• Avoids deep nesting.
• Improves readability.
• Easier error handling using try...catch.
Conclusion
• Node.js Event Model allows non-blocking execution.
• Event Queue stores asynchronous tasks.
• Callbacks execute when an operation completes.
• Event Loop efficiently manages queued tasks.
• Promises & async/await simplify handling asynchronous code.
Web References
1. https://www.geeksforgeeks.org/nodejs/?ref=lbp
2. https://nodejs.org/api/fs.html
3. https://www.tpointtech.com/nodejs-file-system
4. https://www.geeksforgeeks.org/mern-stack/
16