CRUD Operations in Node.js

From the Express.js REST API cheat sheet ยท Routing & REST APIs ยท verified Jul 2026

CRUD Operations

Implement Create, Read, Update, Delete operations following REST conventions

javascript
// Basic CRUD routes
app.get('/api/users', (req, res) => {
  res.json(users);
});

app.get('/api/users/:id', (req, res) => {
  const user = users.find(u => u.id === req.params.id);
  if (!user) return res.status(404).json({ error: 'User not found' });
  res.json(user);
});

app.post('/api/users', (req, res) => {
  const user = { id: Date.now(), ...req.body };
  users.push(user);
  res.status(201).json(user);
});
๐ŸŸข Essential - Standard REST API operations
๐Ÿ’ก Use proper HTTP methods: GET (read), POST (create), PUT/PATCH (update), DELETE
๐Ÿ“Œ Return appropriate status codes: 200 OK, 201 Created, 404 Not Found
โšก Use async/await for cleaner asynchronous code
โš ๏ธ Always validate and sanitize user input
๐Ÿ”— Related: express-validator for input validation

Continue with Express.js REST API

Save the full cheat sheet or work through every related task.

More Node.js tasks

Back to the full Express.js REST API cheat sheet