Unit 3: Backend development and databases
Web Programming-I notes · PTU syllabus (UGDSE301)
On this page
Unit summary
Modern web applications are built as a backend that serves data and a database that stores it. This unit introduces server-side programming with Node.js/Express or PHP, routing GET and POST requests, sessions and cookies, relational and NoSQL databases (MySQL, PostgreSQL, MongoDB), CRUD operations, and JSON-based REST APIs.
After this unit you can
- Explain the role of a backend and create routes with Express.js
- Handle GET and POST requests and manage sessions
- Perform CRUD operations by connecting a backend to a database
- Design and use JSON REST APIs
PTU syllabus topics
- Introduction to server-side programming with Node.js or PHP
- Express.js routing
- handling GET/POST requests
- session and cookie management
- introduction to MySQL/PostgreSQL/MongoDB
- CRUD operations
- connecting backend to database
- JSON and REST APIs
Create
POST
INSERT
Read
GET
SELECT
Update
PUT / PATCH
UPDATE
Delete
DELETE
DELETE
Topic 1
Server-side programming with Node.js and Express
Node.js runs JavaScript on the server; Express.js is a lightweight framework for building web servers and APIs on Node.
javascriptconst express = require("express");
const app = express();
app.use(express.json()); // parse JSON bodies
app.get("/students", (req, res) => { // GET route
res.json([{ roll: 1, name: "Ana" }]);
});
app.post("/students", (req, res) => { // POST route
const s = req.body;
res.status(201).json({ message: "Created", student: s });
});
app.listen(3000);Routing maps a URL and HTTP method to a handler function. Route parameters (/students/:id) read values from the URL.
Topic 2
Sessions and cookies on the server
Express uses middleware such as express-session and cookie-parser; PHP uses session_start() and $_SESSION. Sessions keep users logged in across requests; cookies store a session ID in the browser.
Topic 3
Databases: relational and NoSQL
Structure
Tables with fixed schema
Flexible JSON-like documents
Query language
SQL
Query objects / methods
Relationships
Joins and foreign keys
Embedded documents or references
Best for
Structured, transactional data
Rapidly changing or large unstructured data
Topic 4
CRUD operations
CRUD = Create, Read, Update, Delete — the four basic data operations.
| Operation | SQL | HTTP method | MongoDB |
|---|---|---|---|
| Create | INSERT | POST | insertOne() |
| Read | SELECT | GET | find() |
| Update | UPDATE | PUT / PATCH | updateOne() |
| Delete | DELETE | DELETE | deleteOne() |
php<?php
$conn = new mysqli("localhost", "root", "", "college");
$stmt = $conn->prepare("INSERT INTO student (name, course) VALUES (?, ?)");
$stmt->bind_param("ss", $name, $course); // prepared statement prevents SQL injection
$stmt->execute();
?>Topic 5
JSON and REST APIs
JSON is the standard data format for APIs: {"roll": 1, "name": "Ana", "courses": ["BCA"]}. A REST API exposes resources at URLs and uses HTTP methods to act on them, returning JSON and status codes.
- 200 OK
- Request succeeded
- 201 Created
- A new resource was created
- 400 Bad Request
- Invalid input
- 404 Not Found
- Resource does not exist
- 500 Internal Server Error
- Server-side failure
Exam tip
REST principles: resources identified by URLs, standard HTTP methods, stateless requests and JSON representations.
Key terms
- Backend
- The server-side part of an application handling logic and data
- Express.js
- A minimal web framework for Node.js
- Route
- A mapping from URL and method to a handler
- CRUD
- Create, read, update and delete operations
- REST API
- An interface using URLs and HTTP methods to work with resources
Quick revision
- app.get / app.post define routes in Express.
- SQL: tables and joins; NoSQL: flexible documents.
- CRUD ↔ POST, GET, PUT/PATCH, DELETE.
- Use prepared statements to prevent SQL injection.
- 200 OK, 201 Created, 404 Not Found, 500 Server Error.
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 Node.js?
- Q2.What is routing in Express?
- Q3.Differentiate between SQL and NoSQL databases.
- Q4.Expand CRUD and map it to HTTP methods.
- Q5.What is a REST API?
- Q6.Why are prepared statements used?
Long-answer questions
- Q1.Explain how to build a simple REST API with Express.js for student records.
- Q2.Explain CRUD operations with SQL queries and a PHP-MySQL example.
- Q3.Compare relational and NoSQL databases with examples.
Stuck on this unit?
Message SBS on WhatsApp for help with Web Programming-I, or to ask about studying BCA at Synetic.
