This project consists of two main components:
- React Frontend: A simple form-based application that allows users to submit their email and phone number, sends the data to the server, and displays the results in a styled list.
- Node.js Backend: An Express server that handles the form submission, processes the data, and responds with mock user information after a simulated delay.
Make sure you have the following installed on your machine:
- Node.js (v14 or higher)
- npm or yarn
git clone https://github.com/your-repo-url/fullstack-app.git
cd fullstack-app
You need to make sure that the client knows the backend to knock to: for this in the client dir we need to create .env file:
cd server
touch .env
Open the file and insert this
REACT_APP_BACKEND_URL=http://localhost:8000
where 8000 is the port by default
-
Navigate to the
server
directory (if not already there):cd server
-
Install the backend dependencies:
npm install
-
Start the backend server:
npm run start
By default, the backend server will run on
http://localhost:8000 unless you specify another port in .env like this PORT=...
.
-
Navigate to the
client
directory in a separate terminal window:cd client
-
Install the frontend dependencies:
npm install
-
Start the frontend development server:
npm run start
By default, the frontend server will run on
http://localhost:3000
.
-
Once both servers are running, open your browser and go to:
http://localhost:3000
-
Fill out the form with a valid email and optional phone number, then click the
Submit
button. -
The frontend will send the data to the backend, wait for 5 seconds (simulated delay), and display the list of people in a formatted list.
The backend is a simple Express.js server written in TypeScript that includes:
-
API Endpoint:
POST /api/search
-
Accepts JSON data in the following format:
{ "email": "[email protected]", "number": "22-33-44" }
-
Responds with a simulated list of people after a 5-second delay.
-
-
Request Cancellation: The server can handle request cancellations using
AbortController
if the frontend sends a new request before the previous one completes.
The frontend is a React app built with JS that includes:
- Form with Validation: Utilizes
zod
for email and phone number validation. - Axios Request Handling: Submits the form data to the backend and handles cancellations using
AbortController
. - Styled List Output: Displays the results returned from the backend in a visually appealing format.
- Toast Notifications: Uses
react-toastify
to show success or error messages based on form submission status.
- Changing the Backend Port:
- Modify the port in
backend/index.ts
if needed. - Update the frontend API URL accordingly.
- Modify the port in
- Port Conflicts:
- Make sure no other applications are running on ports
3000
(frontend) and5000
(backend).
- Make sure no other applications are running on ports