Exp 1
Exp 1
Experiment 1
Student Name: Yubin UID: 22BCS16626
Branch: BE CSE Section/Group: IOT-636(B)
Semester: 6th Date of Performance:13-01-25
Subject Name: AP LAB-II Subject Code: 22CSP-351
1. Aim:
Full Stack Development (MERN).The primary aim of this experiment is to provide
students or developers with an understanding of full-stack development involving
MongoDB, Node.js, React, and Express.
• Problem 1.1.1: Give understanding of Mongodb, Nodejs, React, Express.
• Problem 1.1.2: Create a Frontend design of Login/Signup pages and create a backend of it.
Problem Breakdown.
• Problem 1.1.3: Test the Backend API Using Postman.
2. Objective:
• Learn MERN Stack Basics: Understand the key components of the MERN stack
(MongoDB, Express, React, Node.js) and their integration.
• Frontend and Backend Development: Design Login/Signup pages in React and build
secure RESTful APIs using Node.js, Express, and MongoDB.
• Testing with Postman: Validate backend APIs for functionality and error handling.
• Develop and Run a Full-Stack Application: Connect the frontend and backend, deploy the
app, and test the complete workflow.
DEPARTMENT OF
COMPUTER SCIENCE & ENGINEERING
3. Implementation/Code:
// Middleware Configuration
// Enable CORS to allow requests from different origins (useful for frontend-backend
communication)
app.use(cors());
// Mock Database
// In a real-world application, replace this with an actual database such as MongoDB or
//MySQL
let users = [];
// API Endpoints
/**
* @route POST /signup
* @description Handle user signup by storing email and password
* @access Public
*/
app.post("/signup", (req, res) => {
const { email, password } = req.body; // Extract email and password from the request
body
➢ FRONTEND(React)
npx create-react-app client //Create React App
cd client
npm install axios
try {
const response = await fetch("http://localhost:5000/signup", {
method: "POST",
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify({ email, password }),
DEPARTMENT OF
COMPUTER SCIENCE & ENGINEERING
});
return (
<div style={styles.container}>
<div style={styles.box}>
<h2 style={styles.heading}>SIGNUP</h2>
<form onSubmit={handleSignup} style={styles.form}>
<input
type="email"
placeholder="Email"
value={email}
onChange={(e) => setEmail(e.target.value)}
required
style={styles.input}
/>
<input
type="password"
placeholder="Password"
value={password}
onChange={(e) => setPassword(e.target.value)}
required
style={styles.input}
/>
<button type="submit" style={styles.button}>
Signup
</button>
</form>
{message && <p style={styles.successMessage}>{message}</p>}
</div>
</div>
);
};
const styles = {
container: {
display: "flex",
justifyContent: "center",
alignItems: "center",
DEPARTMENT OF
COMPUTER SCIENCE & ENGINEERING
height: "100vh",
background: "linear-gradient(to right, #4facfe, #00f2fe)",
},
box: {
background: "white",
padding: "20px 40px",
borderRadius: "10px",
boxShadow: "0 4px 10px rgba(0, 0, 0, 0.1)",
textAlign: "center",
width: "300px",
},
heading: {
marginBottom: "20px",
color: "#333",
},
form: {
display: "flex",
flexDirection: "column",
},
input: {
marginBottom: "15px",
padding: "10px",
border: "1px solid #ccc",
borderRadius: "5px",
fontSize: "16px",
},
button: {
background: "#00c6ff",
border: "none",
color: "white",
padding: "10px",
fontSize: "16px",
borderRadius: "5px",
cursor: "pointer",
},
successMessage: {
color: "green",
marginTop: "10px",
},
};
4. Output
5. Learning Outcome