TGViewer
Web Development Web Development @webdevcoursefree ยท 79.7K subscribers
Post #3336 5.03K
โœ… CRUD Operations in Back-End Development ๐Ÿ› ๏ธ๐Ÿ“ฆ

Now that youโ€™ve built a basic server, letโ€™s take it a step further by adding full CRUD functionality โ€” the foundation of most web apps.

๐Ÿ” What is CRUD?

CRUD stands for:

โฆ C reate โ†’ Add new data (e.g., new user)
โฆ R ead โ†’ Get existing data (e.g., list users)
โฆ U pdate โ†’ Modify existing data (e.g., change user name)
โฆ D elete โ†’ Remove data (e.g., delete user)

These are the 4 basic operations every back-end should support.

๐Ÿงช Letโ€™s Build a CRUD API

Weโ€™ll use the same setup as before (Node.js + Express) and simulate a database with an in-memory array.

Step 1: Setup Project (if not already)

npm init -y
npm install express


Step 2: Create server.js

const express = require('express');
const app = express();
const port = 3000;

app.use(express.json()); // Middleware to parse JSON

let users = [
{ id: 1, name: 'Alice'},
{ id: 2, name: 'Bob'}
];

// READ - Get all users
app.get('/users', (req, res) => {
res.json(users);
});

// CREATE - Add a new user
app.post('/users', (req, res) => {
const newUser = {
id: users.length + 1,
name: req.body.name
};
users.push(newUser);
res.status(201).json(newUser);
});

// UPDATE - Modify a user
app.put('/users/:id', (req, res) => {
const userId = parseInt(req.params.id);
const user = users.find(u => u.id === userId);
if (!user) return res.status(404).send('User not found');
user.name = req.body.name;
res.json(user);
});

// DELETE - Remove a user
app.delete('/users/:id', (req, res) => {
const userId = parseInt(req.params.id);
users = users.filter(u => u.id!== userId);
res.sendStatus(204);
});

app.listen(port, () => {
console.log(`CRUD API running at http://localhost:${port}`);
});


Step 3: Test Your API

Use tools like Postman or cURL to test:

โฆ GET /users โ†’ List users
โฆ POST /users โ†’ Add user { "name": "Charlie"}
โฆ PUT /users/1 โ†’ Update user 1โ€™s name
โฆ DELETE /users/2 โ†’ Delete user 2

๐ŸŽฏ Why This Matters

โฆ CRUD is the backbone of dynamic apps like blogs, e-commerce, social media, and more
โฆ Once you master CRUD, you can connect your app to a real database and build full-stack apps

Next Steps

โฆ Add validation (e.g., check if name is empty)
โฆ Connect to MongoDB or PostgreSQL
โฆ Add authentication (JWT, sessions)
โฆ Deploy your app to the cloud

๐Ÿ’ก Pro Tip: Try building a Notes app or a Product Inventory system using CRUD!

๐Ÿ’ฌ Double Tap โค๏ธ for more!
  • โค 16
  • ๐Ÿ”ฅ 1
More from @webdevcoursefree
  1. Oct 16, 2026๐——๐—ฎ๐˜๐—ฎ ๐˜€๐—ฐ๐—ถ๐—ฒ๐—ป๐—ฐ๐—ฒ ๐—–๐—ฒ๐—ฟ๐˜๐—ถ๐—ณ๐—ถ๐—ฐ๐—ฎ๐˜๐—ถ๐—ผ๐—ป ๐—ช๐—ถ๐˜๐—ต ๐—”๐—œ๐Ÿ˜ Future Ready Data Scienโ€ฆ
  2. Oct 16, 2026๐ŸŒ Web Development Roadmap โ€” Part 18 HTML Lists Lists are used whenever information needsโ€ฆ
  3. Oct 14, 2026๐ŸŒ Web Development Roadmap โ€” Part 17 HTML Images โ€” <img> Tag Images make webpages more visโ€ฆ
  4. Oct 13, 2026๐—ง๐—ข๐—ฃ ๐—™๐—ฅ๐—˜๐—˜ ๐—–๐—ข๐—จ๐—ฅ๐—ฆ๐—˜๐—ฆ ๐—ง๐—ข ๐—•๐—ข๐—ข๐—ฆ๐—ง ๐—ฌ๐—ข๐—จ๐—ฅ ๐—ฆ๐—ž๐—œ๐—Ÿ๐—Ÿ๐—ฆ ๐—œ๐—ก ๐Ÿฎ๐Ÿฌ๐Ÿฎ๐Ÿฒ! Explorโ€ฆ
  5. Oct 12, 2026For example: Go to Profile โ†’ <a> Submit Form โ†’ <button> Open Article โ†’ <a> Delete Accountโ€ฆ
  6. Oct 12, 2026๐ŸŒ Web Development Roadmap โ€” Part 16 HTML Links โ€” Tag Links are one of the most importantโ€ฆ
Threads Profile ViewerView any public Threads profile without an account.Open ThreadLook โ†’Writing with AI? Make it sound human.Metric37 rewrites AI drafts so they read naturally. Free AI detector, 1,500 words free.Try Metric37 โ†’