Local CloudCode Development

The same database API from CloudCode is available in NodeJS for local development. This may be useful for debugging, or long-running tasks that would exceed the memory or time limits of CloudCode, such as large migration tasks.

Setup

Node 8.10 or later is recommended for built-in async-await support.

Install the journeyapps package with yarn or npm:

yarn add journeyapps
npm install journeyapps

Usage

Here is a sample script:

const { Database, Day } = require("journeyapps");

async function run() {
   const db = await Database.instance({ baseUrl: 'BASE-URL/api/v4/backend-deployment-id', token: process.env.API_TOKEN });
   
   let user = await db.user.first();
   console.log(user.name);  
}

run();

BASE-URL and backend-deployment-id

The sample script above contains BASE-URL and backend-deployment-id placeholders. Please see the Backend API section about HTTP Endpoints to get these values for your deployment.

Run the following from your terminal:

export API_TOKEN=O:ABCDE # From the Manage API page
node script.js

Limitations

  • Some CloudCode-specific functionality, such as task context, automatic DB configuration and scheduling tasks, is not available yet. This may be added in future versions.

  • Only v4 apps are supported. V3 apps must be upgraded to v4 before using this package.

Batch API

When making a large number of database updates, it is strongly recommended to use the Batch API, to reduce the overhead per request.

Last updated