ASSGNMENT
ASSGNMENT
Web Technologies
QUESTION 1 :
The MERN stack is a popular full-stack development framework that combines four key
technologies: MongoDB, Express.js, React.js, and Node.js. Here's a breakdown of each
component and how they work together:
MongoDB is a NoSQL database used to store and manage application data in a flexible,
document-based format.
Express.js is a lightweight and flexible Node.js framework that simplifies server-side application
development.
React.js is a JavaScript library for building interactive and dynamic user interfaces.
Node.js is a JavaScript runtime that allows developers to run JavaScript code on the server side.
1. Frontend (React.js):
o The user interacts with the application through the React.js frontend.
o React sends HTTP requests to the backend to retrieve or send data.
2. Backend (Express.js + Node.js):
o Express.js handles incoming requests from the frontend and defines the
application’s API endpoints.
Node.js executes the Express application, handling server-side logic and routing.
o
3. Database (MongoDB):
o MongoDB stores the data received from the frontend (via the backend) or fetched
for frontend display.
o The backend interacts with MongoDB to perform CRUD operations.
4. Data Flow:
o Frontend: Sends a request (e.g., login, form submission) to the backend.
o Backend: Processes the request, interacts with MongoDB for data, and sends a
response back to the frontend.
o Frontend: Updates the UI based on the backend response.
Summary of Workflow
QUESTION 2:
CODE :
name: '',
email: '',
country: '',
gender: '',
subjects: [],
});
const [errors, setErrors] = useState({});
useEffect(() => {
validateForm();
}, [formData]);
if (!formData.name) {
valid = false;
if (!formData.email || !emailRegex.test(formData.email)) {
valid = false;
if (!formData.country) {
newErrors.country = 'Country is required.';
valid = false;
if (!formData.gender) {
valid = false;
if (formData.subjects.length < 1) {
valid = false;
setErrors(newErrors);
setIsValid(valid);
};
setFormData(prevState => {
? [...prevState.subjects, value]
});
} else {
};
e.preventDefault();
if (isValid) {
setFormData({
name: '',
email: '',
country: '',
gender: '',
subjects: [],
});
} else {
};
return (
<div>
<h1>Registration Form</h1>
<form onSubmit={handleSubmit}>
<div>
<label>Name:</label>
<input
type="text"
name="name"
value={formData.name}
onChange={handleChange}
/>
</div>
<div>
<label>Email:</label>
<input
type="email"
name="email"
value={formData.email}
onChange={handleChange}
/>
{errors.email && <span style={{ color: 'red' }}>{errors.email}</span>}
</div>
<div>
<label>Country:</label>
<select
name="country"
value={formData.country}
onChange={handleChange}
>
<option value="CA">Canada</option>
<option value="MX">Mexico</option>
<option value="AU">Australia</option>
</select>
</div>
<div>
<label>Gender:</label>
<input
type="radio"
name="gender"
value="male"
onChange={handleChange}
/> Male
<input
type="radio"
name="gender"
value="female"
onChange={handleChange}
/> Female
</div>
<div>
<label>Subjects:</label>
<div>
<input
type="checkbox"
name="subjects"
value="Math"
checked={formData.subjects.includes('Math')}
onChange={handleChange}
/> Math
<input
type="checkbox"
name="subjects"
value="Science"
checked={formData.subjects.includes('Science')}
onChange={handleChange}
/> Science
<input
type="checkbox"
name="subjects"
value="History"
checked={formData.subjects.includes('History')}
onChange={handleChange}
/> History
</div>
</div>
<button type="submit">Save</button>
</form>
</div>
);
};
export default App;
OUTPUT :