Full Stack Development - Backend: Important Notes
1. Introduction to Backend Development
- Backend: Server-side part of a web application.
- Handles: Business logic, database operations, authentication, API integrations, etc.
- Common backend languages: Node.js (JavaScript), Python (Django/Flask), PHP, Java (Spring),
Ruby (Rails).
2. HTTP & REST API
- HTTP Methods: GET, POST, PUT, DELETE
- Status Codes:
- 200 OK - Success
- 201 Created - New resource created
- 400 Bad Request - Client error
- 401 Unauthorized
- 404 Not Found
- 500 Internal Server Error
- REST API:
- Stateless architecture.
- Use of standard HTTP methods.
- JSON is the most common data format.
3. Node.js + Express.js (Popular Stack)
- Node.js: JavaScript runtime built on Chrome's V8 engine.
- Express.js: Lightweight web application framework for Node.js.
Basic Server Code:
const express = require('express');
const app = express();
app.get('/', (req, res) => {
res.send('Hello World');
});
app.listen(3000, () => console.log('Server running on port 3000'));
4. Middleware in Express
- Functions that run between request and response.
Example:
app.use(express.json()); // Middleware to parse JSON
5. Routing
- Used to handle different endpoints.
Example:
app.get('/users', (req, res) => { ... });
app.post('/users', (req, res) => { ... });
6. Database (MongoDB / MySQL)
- MongoDB (NoSQL) - stores data in JSON-like documents.
- Mongoose (ODM for MongoDB in Node.js).
MongoDB Example:
const mongoose = require('mongoose');
mongoose.connect('mongodb://localhost/mydb');
const User = mongoose.model('User', { name: String });
const user = new User({ name: 'John' });
user.save();
7. Authentication & Security
- JWT (JSON Web Token) for authentication.
- Store passwords securely using hashing (e.g., bcrypt).
- Avoid SQL injection, XSS, CSRF.
8. Deployment Concepts
- Hosting: Heroku, Render, Vercel, AWS.
- Environment Variables (.env file) for secure config.
9. MVC Architecture
- Model - Data schema.
- View - Frontend (not used in pure backend).
- Controller - Logic to handle requests and responses.
10. Important Terminologies
- CRUD: Create, Read, Update, Delete
- CORS: Cross-Origin Resource Sharing - controls which domains can access your backend.
- API Testing Tools: Postman, Insomnia.