Server-Side Logic

Write Code, Skip Servers

Write JavaScript functions that run securely in the cloud. Triggers, background jobs, scheduled tasks — all the server-side logic you need without managing servers.

Custom Cloud Functions
Cloud Code Triggers
Scheduled & Background Jobs

How Cloud Code Works

Write functions in JavaScript. Deploy to Back4app. Call from any client or trigger automatically on data changes.

Functions

On-demand when called

Client Call
calculate()
[process]
Returns $149.99

Triggers

Auto-run on data change

User signs up
afterSave()
[validate + notify]
Welcome email sent

Jobs

Scheduled (cron)

Every day 9 AM
dailyReport()
[generate]
PDF sent to team
Function Types

Every Type of Backend Logic

From simple API endpoints to complex scheduled workflows — Cloud Code handles it all.

01Cloud Functions

Function Endpoints

Define custom functions that clients can call directly. Perfect for complex business logic that doesn't fit into simple CRUD operations.

  • Define with Parse.Cloud.define()
  • Receive parameters from clients
  • Return any data format
  • Access full Parse SDK and Node.js APIs
  • Call external services and APIs

Your logic, our infrastructure.

// Client call
const
result = await Parse.Cloud.run(
"calculateTotal"
{ orderId: "abc123" }
);
// Returns: { total: 149.99 }
02Triggers

Automatic Data Hooks

Run code automatically when data changes. Validate before saving, send notifications after updates, or modify queries before execution.

  • beforeSave — Validate and transform data
  • afterSave — Side effects after successful save
  • beforeDelete / afterDelete — Cleanup logic
  • beforeFind — Modify queries dynamically
  • beforeLogin / afterLogout — Auth hooks

Data validation without client-side trust.

Trigger Flow
Client
.save()
beforeSave
Validate
Database
Save
afterSave
Notify
03Background Jobs

Long-Running Tasks

Run heavy operations in the background without blocking API responses. Process large datasets, generate reports, or batch update records.

  • Up to 15 minutes execution time
  • No request timeout concerns
  • Progress tracking and logging
  • Trigger manually or from other functions
  • Chain multiple jobs for complex workflows

Heavy lifting without the wait.

Job Progress
Fetching orders...2.3s
Processed 5,000 records45.1s
Generating report...Running
04Scheduled Jobs

Cron-Like Scheduling

Run jobs on a schedule using cron expressions. Daily reports, weekly cleanups, hourly syncs — all automated.

  • Standard cron expression syntax
  • Timezone-aware scheduling
  • Dashboard UI for schedule management
  • Execution history and logs
  • Automatic retries on failure

Set it and forget it.

Schedule
0 9 * * *
Daily at 9:00 AM UTC
Next: Tomorrow at 9:00 AM
Last run: Today at 9:00 AM (success)
Back4app AI Agent
Generate and deploy Cloud Code
Create a beforeSave trigger that validates email format on User class
Generated & Deployed:
Parse.Cloud.beforeSave("User", ...)
MCP Protocol Compatible
AI-Powered Development

Write Cloud Code with AI

Describe the logic you need, and the AI generates, deploys, and tests your Cloud Functions. Focus on what your code should do, not how to write it.

Works with Cursor, VS Code, Windsurf, and more
Generate triggers, functions, and jobs from descriptions
Auto-deploy code to your Back4app app
Debug errors with AI-powered explanations
Refactor and optimize existing functions
Code Examples

Real-World Cloud Code

Copy-paste examples for common use cases.

Cloud Function

Callable

Custom endpoint callable from SDKs

// Define a cloud function
Parse.Cloud.define("calculateOrderTotal", async (request) => {
  const { orderId } = request.params;
  const user = request.user;
  
  // Verify user is authenticated
  if (!user) {
    throw new Error("Must be logged in to calculate order total");
  }
  
  // Query order items
  const Order = Parse.Object.extend("Order");
  const query = new Parse.Query(Order);
  query.equalTo("objectId", orderId);
  query.include("items");
  
  const order = await query.first({ useMasterKey: true });
  
  if (!order) {
    throw new Error("Order not found");
  }
  
  // Calculate total with tax
  const items = order.get("items") || [];
  const subtotal = items.reduce((sum, item) => 
    sum + (item.get("price") * item.get("quantity")), 0
  );
  const tax = subtotal * 0.08;
  const total = subtotal + tax;
  
  // Update order with calculated total
  order.set("subtotal", subtotal);
  order.set("tax", tax);
  order.set("total", total);
  await order.save(null, { useMasterKey: true });
  
  return { subtotal, tax, total };
});
Use Cases

What Can You Build?

Cloud Functions power critical backend logic across industries.

Data Validation

Enforce business rules server-side. Validate inputs, check constraints, and reject invalid data before it's saved.

Payment Processing

Integrate with Stripe, PayPal, or other processors. Handle webhooks, validate payments, update order status.

Email Notifications

Send transactional emails on data changes. Welcome emails, order confirmations, password resets.

Third-Party APIs

Connect to external services. Weather data, social media, analytics, AI services — all from your backend.

Report Generation

Generate PDFs, spreadsheets, or data exports. Run as background jobs for large datasets.

Data Sync

Keep data in sync with external systems. CRM updates, inventory sync, analytics pipelines.

FAQ

Frequently Asked Questions

What language do Cloud Functions use?
Cloud Functions are written in JavaScript (Node.js). You can use modern syntax, async/await, and import npm packages. The runtime supports Node.js with access to the Parse Server SDK.
What are triggers (beforeSave, afterSave, etc.)?
Triggers are special functions that run automatically when specific events occur. beforeSave runs before an object is saved (for validation), afterSave runs after (for side effects), beforeDelete/afterDelete for deletions, and beforeFind for query modification.
How do I schedule recurring jobs?
Define a job function in your Cloud Code, then schedule it directly from the Back4app Dashboard. Configure the schedule using a simple interface—no manual cron syntax required.
Can Cloud Functions call external APIs?
Yes. Cloud Functions can make HTTP requests to any external API using fetch or axios. This is perfect for integrating with payment processors, email services, or third-party data sources.
How do I debug Cloud Functions?
Use console.log() statements and view logs in the Back4app dashboard. For local development, you can run Parse Server locally and test your functions before deploying.
Are there execution time limits?
Cloud Functions have a 60-second timeout for synchronous operations. For longer tasks, use Background Jobs which can run for up to 15 minutes. You can also chain jobs for very long processes.
Can I use npm packages in Cloud Functions?
Yes. Add dependencies to your package.json in the Cloud Code directory. Popular packages like axios, lodash, moment, and stripe are commonly used. Deploy via CLI or dashboard.

Deploy Your First Function Today

Write server-side logic without managing servers. No credit card required.