Cara Buat REST API dengan Node.js dan Express

REST API itu backbone dari hampir semua aplikasi modern. Di tutorial ini aku bakal jelasin cara bikin dari nol. Setup Project mkdir my-api && cd my-api npm init -y npm install express dotenv cors helmet morgan Basic Server const express = require('express'); const app = express(); const PORT = process.env.PORT || 3000; app.use(express.json()); app.get('/', (req, res) => { res.json({ message: 'API is running!' }); }); app.listen(PORT, () => { console.log(`Server running on port ${PORT}`); }); CRUD Operations // GET all app.get('/api/users', (req, res) => { res.json(users); }); // GET single app.get('/api/users/:id', (req, res) => { const user = users.find(u => u.id === parseInt(req.params.id)); if (!user) return res.status(404).json({ error: 'Not found' }); res.json(user); }); // POST create app.post('/api/users', (req, res) => { const newUser = { id: nextId++, ...req.body }; users.push(newUser); res.status(201).json(newUser); }); // PUT update app.put('/api/users/:id', (req, res) => { const index = users.findIndex(u => u.id === parseInt(req.params.id)); if (index === -1) return res.status(404).json({ error: 'Not found' }); users[index] = { ...users[index], ...req.body }; res.json(users[index]); }); // DELETE app.delete('/api/users/:id', (req, res) => { const index = users.findIndex(u => u.id === parseInt(req.params.id)); if (index === -1) return res.status(404).json({ error: 'Not found' }); users.splice(index, 1); res.status(204).send(); }); Best Practices Versioning - /api/v1/users Pagination - ?page=1&limit=10 Error handling Input validation Rate limiting Conclusion Dalam 1 jam, kamu udah punya REST API yang functional. ...

13 Februari 2026 · 2 menit · Dovi

Cara Build Telegram Bot dengan AI (Node.js + OpenAI)

Telegram bot itu powerful banget, apalagi kalau dikasih AI. Bayangin punya bot yang bisa jawab pertanyaan, summarize artikel, bahkan nulis kode. Di tutorial ini aku bakal ngejelasin cara bikin Telegram bot pakai Node.js dan OpenAI API. Persiapan Telegram Bot Token - Dapet dari @BotFather OpenAI API Key - Dari platform.openai.com Node.js 18+ - Sudah terinstall Code Editor - VS Code atau sejenisnya Step 1: Buat Bot di Telegram Buka Telegram, cari @BotFather Kirim /newbot Kasih nama bot (misal: “My AI Bot”) Kasih username (harus unik, diakhiri ‘bot’) Simpan token yang dikasih Step 2: Setup Project mkdir my-ai-bot cd my-ai-bot npm init -y npm install node-telegram-bot-api openai dotenv Buat file .env: ...

1 Desember 2025 · 4 menit · Dovi