Skip to content

Commit

Permalink
Update README.md
Browse files Browse the repository at this point in the history
  • Loading branch information
charlypoly authored Feb 26, 2023
1 parent e305c8e commit 53fe187
Showing 1 changed file with 10 additions and 46 deletions.
56 changes: 10 additions & 46 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,54 +1,18 @@
# `@defer/client`

`defer` is your favorite background tasks handler to offload your JavaScript API.
Zero infrastructure Node.js background jobs.

----

## Install
## Get started

- [Next.js Quickstart](https://docs.defer.run/quickstart/next/)
- [Express/Koa/hapi Quickstart](https://docs.defer.run/quickstart/express-koa-hapi/)

```sh
yarn add @defer/client

# or
## API documentation

npm i @defer/client
```

## Configuration

Make sure to define the `DEFER_TOKEN` environment variable in production/staging environments.

## Usage


### 1. Define your background function

A background function should be a unique default export of a file placed in `background-functions/` folder.

```ts
import { defer } from "@defer/client";

function importContacts(intercomId: string) {
// import contacts from Hubspot and insert them in the database
}

export default defer(importContacts)
```


### 2. Call your background function

For a seamless integration with your project, we recommend to install our `@defer.run/babel` babel plugin.
Our babel plugin will replace all usage of defer functions to client pushes:

```ts
import type { NextApiRequest, NextApiResponse } from "next";
import sentToIntercom from "../../background-functions/importContacts";

export default function handler(req: NextApiRequest, res: NextApiResponse) {
// will be executed in the background
await importContacts(currentUser.intercomId);

res.status(200).json({ name: "John Doe" });
}
```
- [Configuration options: retries, concurrency](https://docs.defer.run/features/retries-concurrency/)
- [Delayed Function](https://docs.defer.run/features/delay/)
- [CRON](https://docs.defer.run/features/cron/)
- [Workflows](https://docs.defer.run/features/workflows/)

0 comments on commit 53fe187

Please sign in to comment.