# 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](https://www.npmjs.com/package/journeyapps) package with `yarn` or `npm`:

```shell
yarn add journeyapps
```

```shell
npm install journeyapps
```

### Usage

Here is a sample script:

```javascript
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();
```

{% hint style="info" %}
**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](#http-endpoints) to get these values for your deployment.
{% endhint %}

Run the following from your terminal:

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

{% hint style="warning" %}
**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.
  {% endhint %}

### Batch API

When making a large number of database updates, it is strongly recommended to use the [Batch API](https://docs.journeyapps.com/reference/cloudcode/advanced-cloudcode-topics/batch-api-cloudcode), to reduce the overhead per request.

###
