Quick Reference Cheat Sheet - Documentation

← Back to Docs Raw Markdown JSON API

Quick Reference Cheat Sheet

🚀 Quick Commands

Add New API Endpoint

# 1. Edit routes/api.js - add your endpoint
# 2. Test locally
PORT=3001 npm start

# 3. Test endpoint
curl "http://localhost:3001/api/your-endpoint"

# 4. Deploy
git add . && git commit -m "Add new API endpoint"
# Then use manual deployment method

Add New HTML Page

# 1. Add route to routes/pages.js
# 2. Create view in views/your-page.ejs  
# 3. Update navigation in views/layout.ejs
# 4. Test and deploy

Add New Documentation

# 1. Create content/your-doc.md
# 2. Auto-appears at /docs
# 3. Available at /docs/your-doc

📁 File Structure Quick Reference

api/
├── app.js                 # Main server entry point
├── package.json           # Dependencies and scripts
├── Procfile              # Dokku process definition
├── Dockerfile            # Container configuration
├── routes/
│   ├── api.js            # JSON API endpoints
│   ├── pages.js          # HTML page routes
│   └── docs.js           # Documentation system
├── views/
│   ├── layout.ejs        # Base template
│   ├── index.ejs         # Home page
│   ├── about.ejs         # About page
│   └── [other-pages].ejs # Additional pages
├── content/
│   ├── api-reference.md  # API documentation
│   ├── deployment.md     # Deployment guide
│   └── [your-docs].md    # Your documentation
└── public/
    ├── css/style.css     # Styles
    └── js/app.js         # Client-side JS

🌐 Live URLs

🔧 Common API Patterns

GET Endpoint with Query Parameters

router.get('/items', (req, res) => {
  const { limit = 10, category } = req.query;
  let results = data;
  
  if (category) {
    results = data.filter(item => item.category === category);
  }
  
  results = results.slice(0, parseInt(limit));
  
  res.json({
    success: true,
    count: results.length,
    data: results
  });
});

GET Endpoint with Path Parameters

router.get('/items/:id', (req, res) => {
  const item = data.find(i => i.id === parseInt(req.params.id));
  
  if (!item) {
    return res.status(404).json({
      success: false,
      message: 'Item not found'
    });
  }
  
  res.json({
    success: true,
    data: item
  });
});

POST Endpoint

router.post('/items', (req, res) => {
  const { name, category } = req.body;
  
  if (!name || !category) {
    return res.status(400).json({
      success: false,
      message: 'Name and category are required'
    });
  }
  
  const newItem = {
    id: Date.now(),
    name,
    category,
    created: new Date().toISOString()
  };
  
  data.push(newItem);
  
  res.status(201).json({
    success: true,
    data: newItem
  });
});

🎨 EJS Template Patterns

Basic Page Template

<div class="card">
    <div class="card-header">
        <h1><%= title %></h1>
    </div>
    <div class="card-body">
        <p><%= description %></p>
        <!-- Your content -->
    </div>
</div>

Data Iteration

<% if (items && items.length > 0) { %>
    <ul>
        <% items.forEach(item => { %>
            <li>
                <strong><%= item.name %></strong>
                <span><%= item.category %></span>
            </li>
        <% }) %>
    </ul>
<% } else { %>
    <p>No items found.</p>
<% } %>

Conditional Content

<% if (user.isAdmin) { %>
    <div class="admin-panel">
        <h3>Admin Controls</h3>
        <!-- Admin content -->
    </div>
<% } %>

📋 Deployment Checklist

  • Test locally on port 3001
  • Commit changes to git
  • Create deployment archive
  • Upload to server
  • Build and deploy Docker container
  • Verify health endpoint
  • Test new features
  • Check logs for errors

🐛 Troubleshooting

Port Issues

# Kill processes on port 3000
lsof -ti:3000 | xargs kill -9 2>/dev/null || true

Container Issues

# Check container status
ssh root@104.248.219.197 "docker ps -a | grep api"

# View logs
ssh root@104.248.219.197 "docker logs api.web.1 --tail 20"

# Restart container
ssh root@104.248.219.197 "docker restart api.web.1"

Git Issues

# Reset if needed
git reset --hard HEAD
git clean -fd

# Force push if necessary
git push origin main --force

🔍 Testing Commands

# Health check
curl "https://api.app.lobott.com/health"

# API endpoints
curl "https://api.app.lobott.com/api"
curl "https://api.app.lobott.com/api/users"
curl "https://api.app.lobott.com/api/search?q=test"

# With JSON formatting
curl -s "https://api.app.lobott.com/api/users" | jq .

This cheat sheet provides quick access to the most common operations for your Multi-API application.