Loading...
By KarnatakaPUCS Team on 7/10/2026
REST APIs are the backbone of modern web applications. Learn to build them with Node.js and Express.
bashmkdir my-api && cd my-api npm init -y npm install express
javascriptconst express = require('express'); const app = express(); const PORT = 3000; // Middleware app.use(express.json()); // Routes app.get('/', (req, res) => { res.json({ message: 'Welcome to the API' }); }); app.listen(PORT, () => { console.log(`Server running on port ${PORT}`); });
javascriptapp.get('/api/users', (req, res) => { res.json(users); });
javascriptapp.post('/api/users', (req, res) => { const newUser = req.body; users.push(newUser); res.status(201).json(newUser); });
javascriptapp.put('/api/users/:id', (req, res) => { const { id } = req.params; const updatedUser = req.body; // Update logic here res.json(updatedUser); });
javascriptapp.delete('/api/users/:id', (req, res) => { const { id } = req.params; // Delete logic here res.status(204).send(); });