Node.js Core & Express Backend APIs
18 mins read
Free Lesson
Scaffold an Express web server, handle GET, POST, PUT, DELETE routes, and parse JSON payloads.
Express.js REST API Scaffolding
const express = require('express');
const app = express();
app.use(express.json()); // Built-in JSON body parser
const courses = [
{ id: 1, title: 'Node.js Masterclass', is_free: true }
];
app.get('/api/courses', (req, res) => {
res.status(200).json(courses);
});
app.post('/api/courses', (req, res) => {
const newCourse = { id: courses.length + 1, ...req.body };
courses.push(newCourse);
res.status(201).json(newCourse);
});
app.listen(3000, () => console.log('Server running on port 3000'));