AP Ex-1
AP Ex-1
Experiment 1
Student Name: Zatch UID:
Branch: CSE Section/Group:
Semester: 6 Date of Performance:
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.
1. Problem 1.1.1: Give understanding of MongoDB, Nodejs, React, Express.
2. Problem 1.1.2: Create a Frontend design of Login/Signup pages and create a
backend of it.
3. Problem 1.1.3: Test the Backend API Using Postman
2. Objective:
• Understand the fundamentals of MongoDB, Node.js, React, and Express
• Create a functional frontend for Login/Signup pages
• Develop a backend using Express and MongoDB
• Test the backend API using Postman
3. Implementation/Code:
Backend:
• mkdir backend cd backend
• npm init -y npm install
• express mongoose cors bcryptjs jsonwebtoken
Server.js
const express = require('express');
DEPARTMENT OF
COMPUTER SCIENCE & ENGINEERING
dotenv.config();
// Connect to MongoDB
const mongoose = require('mongoose');
module.exports = User;
app.use('/api', authRoutes);
DEPARTMENT OF
COMPUTER SCIENCE & ENGINEERING
// Start Server
const port = 5000;
app.listen(port, () => {
console.log(`Server running on http://localhost:${port}`);
});
Users.js
});
authRoutes.js
// Signup Route
try {
if (existingUser) {
await newUser.save();
} catch (error) {
});
try {
if (!user) {
if (!isMatch) {
} catch (error) {
});
my-auth-app:
App.jsx:
// In App.js or index.js
import './index.css';
import './app.css';
return (
DEPARTMENT OF
COMPUTER SCIENCE & ENGINEERING
<Router>
<div className="App">
<Routes>
</Routes>
</div>
</Router>
);
};
4. Output:
DEPARTMENT OF
COMPUTER SCIENCE & ENGINEERING
5. Learning Outcome:
• Design user-friendly forms for user login and registration using React..
• Learn how each technology works individually and how they integrate to form
a full-stack application.
• Set up a server with Express to handle HTTP requests for user registration and
login
• Verify that the backend API functions as expected by testing the registration
and login endpoints with Postman