Tips > Data, APIs & Webhooks

Set Up a Development Instance with Mock Data

Never test against production APIs when you can avoid it.

Never test against production APIs when you can avoid it. Run a separate n8n development instance that uses mock data, test credentials, and sandbox API endpoints. This eliminates accidental production side effects and keeps test costs at zero.

Real-world example: Your team builds workflows that interact with Stripe, SendGrid, and Salesforce. Testing against production risks sending real emails, charging real cards, and polluting CRM data.


# docker-compose.dev.yml -- Development n8n instance

version: '3.8'
services:
  n8n-dev:
    image: n8nio/n8n:latest
    ports:
      - "5679:5678"    # Different port from production

    environment:
      - N8N_HOST=localhost
      - N8N_PORT=5678
      - N8N_PROTOCOL=http
      - WEBHOOK_URL=http://localhost:5679/
      - NODE_ENV=development
      # Use sandbox/test API keys

      - STRIPE_API_KEY=sk_test_xxxxxxxxxxxx
      - SENDGRID_API_KEY=SG.test_xxxxxxxxxxxx
    volumes:
      - n8n_dev_data:/home/node/.n8n
```text
Create mock API endpoints using a simple n8n workflow on the dev instance:

```javascript
// Code node in a "Mock API" workflow
// Webhook path: mock/stripe/charges
const mockResponses = {
  'charges': {
    id: 'ch_mock_' + Date.now(),
    amount: 2000,
    currency: 'usd',
    status: 'succeeded',
    created: Math.floor(Date.now() / 1000)
  },
  'customers': {
    id: 'cus_mock_' + Date.now(),
    email: 'test@example.com',
    name: 'Test Customer'
  }
};

const resource = $input.first().json.params.resource || 'charges';
return [{
  json: mockResponses[resource] || { error: 'Unknown resource' }
}];
```text
```yaml
Credential management strategy:
  Production instance:
    - Real API keys stored in n8n credentials
    - Workflows activated and processing live data

  Development instance:
    - Test/sandbox API keys only
    - Mock workflows for services without sandboxes
    - All workflows default to inactive
    - Pinned test data for common scenarios
```text
> **Tip: Use n8n's environment variable credentials**
>
> Store API keys as environment variables (`STRIPE_API_KEY`, etc.) and reference them in credentials. Switching between dev and prod is then just a matter of which environment file is loaded -- the workflows themselves do not change.

This prevents the "I accidentally emailed 10,000 customers from my test workflow" disaster.

**Related:** [Use Structured Output (JSON Mode) for Parseable Responses](../ai-and-llm-integration/01-use-structured-output-json-mode-for-parseable-responses.md) | [Configure Payload Size and Binary Data Mode for Large Files](../performance-and-large-files/01-configure-payload-size-and-binary-data-mode-for-large-files.md)

Showcase builds

19 complete workflows from my own projects, each with its n8n workflow JSON to import. Showcase entries link the file at the end of the article.

See the showcase builds

Keep reading

191 entries grouped by topic, from first workflow to queue mode. Free, no signup.

Browse the encyclopedia

Need it built?

I design, build and run n8n systems for clients. Every engagement starts with a $1,500 diagnostic audit, credited toward the build.

Book a 20-minute call