What is Basic knowledge of Redis, PM2, and Nginx?
Here’s a basic overview of Redis, PM2, and Nginx—three important tools often used in web development and server management:
🧠 Redis (Remote Dictionary Server)
Redis is an in-memory data structure store, used as a database, cache, and message broker.
Basic Knowledge:
- In-memory: Data is stored in RAM, making it extremely fast.
- Key-value store: Similar to a JavaScript object or Python dictionary.
- Common use cases:
- Caching (e.g., session data, frequently accessed queries)
- Pub/Sub messaging
- Queues and rate limiting
- Data types: Strings, Lists, Sets, Hashes, Sorted Sets.
- Commands:
SET
,GET
,DEL
,INCR
,EXPIRE
, etc. - Redis persists data using snapshots (
RDB
) or logs (AOF
), though it’s primarily used for performance over persistence.
🔁 PM2 (Process Manager 2)
PM2 is a production process manager for Node.js applications.
Basic Knowledge:
- Manages Node.js processes, ensuring your app stays online.
- Supports features like:
- Process monitoring
- Automatic restarts on crash or code changes
- Log management
- Cluster mode to take advantage of multi-core CPUs
- Common commands:
pm2 start app.js
: Start an apppm2 restart app
: Restart itpm2 stop app
: Stop itpm2 logs
: View logspm2 list
: See running apps
- Saves the process list with
pm2 save
and restores on boot withpm2 startup
.
🌐 Nginx (Engine-X)
Nginx is a high-performance web server, also used as a reverse proxy, load balancer, and HTTP cache.
Basic Knowledge:
- Can serve static files (HTML, CSS, images).
- Often used as a reverse proxy to forward client requests to backend services (like a Node.js app).
- Helps with SSL termination, compression, and rate limiting.
- Configuration is done via
/etc/nginx/nginx.conf
and site files in/etc/nginx/sites-available/
. - Example use:
- Serve frontend assets
- Proxy API requests to an Express app
- Handle HTTPS using Let’s Encrypt
Basic config snippet:
server {
listen 80;
server_name example.com;
location / {
proxy_pass http://localhost:3000;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
}
}