# @freshbooks/app

> ExpressJS app for FreshBooks API

Latest version **3.0.7** (published 2024-09-11) · MIT license · 0 weekly downloads

## Install

```sh
npm install @freshbooks/app
pnpm add @freshbooks/app
yarn add @freshbooks/app
bun add @freshbooks/app
```

## Health

**Score 35/100 (D)** — status: abandoned.

Positive: has types; no vulnerabilities; high quality score.

Warnings: low downloads; no esm support.

Negative: abandoned.

## Facts

| | |
|---|---|
| Version | 3.0.7 |
| Published | 2024-09-11 |
| First published | 2020-12-14 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 7 |
| Unpacked size | 14 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 11 |
| Author | FreshBooks |
| Maintainers | mohannedabbas, mario.jankovic, jsawatzky, nachiket.galande, sysadminfreshbooks, amcintoshfb |

## Links

- npm: https://www.npmjs.com/package/@freshbooks/app
- Repository: https://github.com/freshbooks/freshbooks-nodejs-sdk
- Homepage: https://github.com/freshbooks/freshbooks-nodejs-sdk#readme
- Issues: https://github.com/freshbooks/freshbooks-nodejs-sdk/issues
- npm.io page: https://npm.io/package/@freshbooks/app

## Dependencies (7)

- [helmet](https://npm.io/package/helmet.md) ^6.0.1
- [express](https://npm.io/package/express.md) ^4.17.1
- [winston](https://npm.io/package/winston.md) ^3.3.1
- [passport](https://npm.io/package/passport.md) ^0.7.0
- [@freshbooks/api](https://npm.io/package/@freshbooks/api.md) ^4.1.0
- [express-session](https://npm.io/package/express-session.md) ^1.17.0
- [passport-oauth2](https://npm.io/package/passport-oauth2.md) ^1.5.0

## Recent versions

- 3.0.7 (latest) — 2024-09-11
- 3.0.6 — 2023-03-29
- 3.0.6-alpha.1 — 2023-02-15
- 3.0.6-alpha.0 — 2023-02-07
- 3.0.5 — 2022-12-22
- 3.0.4 — 2022-12-21
- 3.0.3 — 2022-11-29
- 3.0.2 — 2022-11-08
- 3.0.1 — 2022-09-27
- 3.0.0 — 2022-01-24
- 2.0.2 — 2021-10-18
- 2.0.1 — 2021-10-13
- 2.0.0 — 2021-10-01
- 1.0.31 — 2021-06-01
- 1.0.30 — 2021-06-01
- … 11 more at https://npm.io/package/@freshbooks/app/versions

## README

# FreshBooks NodeJS SDK

![](https://github.com/freshbooks/api-sdk/workflows/Node%20CI/badge.svg)

The FreshBooks NodeJS SDK is a collection of single-purpose packages designed to easily build FreshBooks apps. Each package delivers part of the FreshBooks [REST API](https://www.freshbooks.com/api), so that you can choose the packages that fit your needs.

| Package                             | What it's for                                                                                                                 |
| ----------------------------------- | ----------------------------------------------------------------------------------------------------------------------------- |
| [`@freshbooks/api`](https://www.npmjs.com/package/@freshbooks/api) | Get/set data from FreshBooks using the REST API.                                                                              |
| [`@freshbooks/app`](https://www.npmjs.com/package/@freshbooks/api) | Pre-configured [ExpressJS](https://expressjs.com/) app. Includes authentication via [PassportJS](http://www.passportjs.org/). |

## Installation

Use your favorite package manager to install any of the packages and save to your `package.json`:

```shell
$ npm install @freshbooks/api @freshbooks/app

# Or, if you prefer yarn
$ yarn add @freshbooks/api @freshbooks/app
```

## Usage

### `@freshbooks/app`

The FreshBooks SDK provides a pre-configured `ExpressJS` app. This app provides OAuth2 authentication flow, a `PassportJS` middleware for authenticating requests, and session middleware to retrieve tokens for a session.

#### Using the ExpressJS app

Setting up the ExpressJS app requires a FreshBooks `client__id` and `client_secret`, as well as a callback URL to receive user authentication and refresh tokens. Once configured, routes can be configured as in any other `ExpressJS` app.

```typescript
import { Client } from '@freshbooks/api'
import createApp from '@freshbooks/app'

const CLIENT_ID = process.env.CLIENT_ID
const CLIENT_SECRET = process.env.CLIENT_SECRET
const CALLBACK_URL = process.env.CALLBACK_URL

const app = createApp(CLIENT_ID, CLIENT_SECRET, CALLBACK)

// set up callback route
app.get('/auth/freshbooks/redirect', passport.authorize('freshbooks')

// set up an authenticated route
app.get('/settings', passport.authorize('freshbooks'), async (req, res) => {
  // get an API client
  const { token } = req.user
  const client = new Client(CLIENT_ID, token)

  // fetch the current user
  try {
    const { data } = await client.users.me()
    res.send(data.id)
  } catch ({ code, message }) {
    res.status(500, `Error - ${code}: ${message}`)
  }
})
```

---
_Source: https://npm.io/package/@freshbooks/app · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
