L9. ๐ ๏ธ Node.js + Express โ CRUD Operations

1 min read
// CRUD OPERATIONS ๐งฉ
// C = Create | R = Read | U = Update | D = Delete
// Creating server using Express โ๏ธ
import express from 'express';
const app = express(); // express app instance
// C = Create => POST method (e.g., posting pic on Instagram ๐ธ)
// R = Read => GET method (e.g., seeing posts on Instagram ๐)
// U = Update => PUT method (e.g., editing a post โ๏ธ)
// D = Delete => DELETE method (e.g., deleting a post โ)
// To handle each operation, we use specific HTTP methods ๐
// Read data (GET request) ๐ฅ
app.get('/get', (req, res) => {
res.send("GET request");
});
// Create data (POST request) โ
app.post('/post', (req, res) => {
res.send("POST request");
});
// You can later add PUT and DELETE here for full CRUD
// Run the server on port 2000 ๐ช
const port = 2000;
app.listen(port, () => console.log(`Server is running on port ${port}`));
โจ Explanation
Express.js makes it easier to handle HTTP methods like GET, POST, PUT, DELETE.
app.get()
handles reading data (like viewing posts).app.post
()
handles creating data (like uploading a photo).You can add
app.put()
andapp.delete()
for full CRUD.CRUD is the basic of any backend system and is used in almost every app.
0
Subscribe to my newsletter
Read articles from Sahana S Acharya directly inside your inbox. Subscribe to the newsletter, and don't miss out.
Written by
