Unit 3: Integration and deployment
Web Programming-II notes · PTU syllabus (UGDSE303)
On this page
Unit summary
The final step is joining the React frontend to the Node/Express backend, securing it, and putting it online. This unit covers connecting the two, CORS, API requests from forms, JWT authentication and login/signup flows, full-stack project structure, and deployment with environment variables.
After this unit you can
- Connect a React frontend to an Express API and handle CORS
- Submit forms to an API and handle responses and errors
- Implement JWT-based login and signup
- Structure, configure and deploy a full-stack project
PTU syllabus topics
- Connecting React frontend with Node/Express API
- CORS
- form submission and API requests
- JWT authentication
- login/signup workflow
- full-stack project structure and best practices
- deployment to Netlify/Render/Vercel/Heroku
- environment variables
- 1Login
User sends credentials
- 2Issue token
Server returns a signed JWT
- 3Call API
Client sends the token with requests
- 4Verify
Server checks the token
- 5Respond
Returns protected data
Topic 1
Connecting frontend and backend, and CORS
The React app (for example on localhost:3000) calls the API (on localhost:5000) with fetch or axios. Because they run on different origins, the browser blocks the requests unless the server allows them — CORS (Cross-Origin Resource Sharing).
javascriptconst cors = require("cors");
app.use(cors({ origin: "http://localhost:3000" }));Topic 2
Form submission and API requests
jsxasync function handleSubmit(e) {
e.preventDefault();
const res = await fetch("/api/tasks", {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({ title }),
});
if (!res.ok) setError("Could not save");
}Topic 3
JWT authentication
- 1
User submits email and password
- 2
Server checks the hashed password
bcrypt.compare
- 3
Server signs a JWT
jwt.sign({ id }, SECRET, { expiresIn: "1h" })
- 4
Client stores the token
- 5
Client sends it on each request
Authorization: Bearer <token>
- 6
Middleware verifies it
jwt.verify before protected routes
A JWT (JSON Web Token) has three parts — header, payload and signature — and lets the server confirm a user's identity without storing sessions. Passwords must be hashed (bcrypt) at signup.
Topic 4
Project structure and best practices
| Folder | Contents |
|---|---|
| client/ | React app: components, pages, services |
| server/routes | Express route files |
| server/controllers | Request-handling logic |
| server/models | Database schemas (Mongoose/SQL) |
| server/middleware | Auth, error handling |
| .env | Secrets and configuration (never committed) |
Best practices: validate input on the server, handle errors centrally, keep secrets in environment variables, and use Git.
Topic 5
Deployment and environment variables
- Frontend: build with
npm run buildand deploy to Netlify or Vercel. - Backend: deploy to Render, Railway or a similar host; use a cloud database (MongoDB Atlas).
- Environment variables (
process.env.MONGO_URI,JWT_SECRET) keep configuration out of the code and differ between development and production.
Key terms
- CORS
- Browser rule controlling cross-origin requests
- JWT
- A signed token proving a user's identity
- bcrypt
- A library for hashing passwords
- Environment variable
- Configuration stored outside the code
- Deployment
- Making an application available online
Quick revision
- Enable CORS on the server for the frontend origin.
- Send JSON with Content-Type: application/json.
- JWT: sign on login, send as Bearer token, verify in middleware.
- Secrets in .env; frontend to Netlify/Vercel, backend to Render.
Important exam questions
Practice questions written to the PTU exam pattern for this unit's syllabus: short answers (Section A style) and long answers (Sections B and C style).
Short-answer questions
- Q1.What is CORS and why is it needed?
- Q2.What are the three parts of a JWT?
- Q3.Why should passwords be hashed?
- Q4.What are environment variables used for?
- Q5.Name two platforms for deploying a React app.
Long-answer questions
- Q1.Explain how a React frontend communicates with an Express backend, including CORS.
- Q2.Explain JWT-based authentication with a login and signup workflow.
- Q3.Describe the structure and deployment of a full-stack MERN application.
Stuck on this unit?
Message SBS on WhatsApp for help with Web Programming-II, or to ask about studying BCA at Synetic.
