# ghost-storage-base

> Base class for Ghost storage adapters.

Latest version **3.0.0** (published 2026-07-24) · MIT license · 0 weekly downloads

## Install

```sh
npm install ghost-storage-base
pnpm add ghost-storage-base
yarn add ghost-storage-base
bun add ghost-storage-base
```

## Health

**Score 85/100 (A)** — status: active.

Positive: has types; esm support; no vulnerabilities; has provenance; recently updated; high maintenance score; high quality score; popular repo; extremely popular.

Warnings: low downloads.

## Facts

| | |
|---|---|
| Version | 3.0.0 |
| Published | 2026-07-24 |
| First published | 2017-04-05 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Dependencies | 1 |
| Unpacked size | 12.3 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Provenance | attested (GitHub Actions) |
| GitHub stars | 55436 |
| Author | Ghost Foundation |
| Maintainers | zimoatghost, allouis, kernalghost, chrisraible, erisds, johnonolan, kevinansfield, cobbspur, aileencgn, jloh, minimaluminium, sam-lord, pauladamdavis, bobvaneck, joeegrigg, hadret, jonhickman, erik-ghost, sagzy, vershwal, zach1618, mike182uk, luissazevedo, lsinger, nickmoreton, renatoworks, rblstr-ghost, evanhahn-ghost, austin.burdine, weylandswart, ghost-slimer, tmciesco, jonatan-ghost, 9larsons, kirrg001 |
| Keywords | ghost, storage, adapter |

## Links

- npm: https://www.npmjs.com/package/ghost-storage-base
- Repository: https://github.com/TryGhost/Ghost
- npm.io page: https://npm.io/package/ghost-storage-base

## Dependencies (1)

- [moment](https://npm.io/package/moment.md) 2.30.1

## Alternatives

- [localforage](https://npm.io/package/localforage.md) — 6.2M weekly downloads
- [localforage-observable](https://npm.io/package/localforage-observable.md) — 30.8K weekly downloads
- [@y/y](https://npm.io/package/@y/y.md) — 30.1K weekly downloads
- [@metaobjectsdev/render](https://npm.io/package/@metaobjectsdev/render.md) — 3.5K weekly downloads
- [@ledgerhq/coin-algorand](https://npm.io/package/@ledgerhq/coin-algorand.md) — 1.1K weekly downloads

## Recent versions

- 3.0.0 (latest) — 2026-07-24
- 2.1.5 — 2026-06-25
- 2.1.2 — 2026-06-24
- 2.1.0 — 2026-06-22
- 2.0.0 — 2026-06-11
- 1.1.2 — 2026-02-09
- 1.1.1 — 2025-01-30
- 1.1.0 — 2025-01-29
- 1.0.0 — 2021-11-09
- 0.0.6 — 2021-09-08
- 0.0.5 — 2020-05-26
- 0.0.4 — 2020-03-03
- 0.0.3 — 2018-04-30
- 0.0.2 — 2018-03-21
- 0.0.1 — 2017-04-05

## README

# ghost-storage-base

Base class for [Ghost](https://ghost.org) storage adapters. A storage adapter
decides where uploaded images, media, and files are stored and how they're
served — the local filesystem, S3, Google Cloud Storage, etc.

See the [Ghost adapters documentation](https://docs.ghost.org/config#adapters)
for how adapters are configured and loaded.

## Usage

Install the base class alongside your adapter:

```bash
npm install ghost-storage-base
```

Extend `StorageBase` and implement every method listed in `requiredFns`:
`exists`, `save`, `serve`, `delete`, and `read`. TypeScript adapters must also
implement the declared `saveRaw(buffer, targetPath)` and `urlToPath(url)`
methods.

```js
const {StorageBase} = require('ghost-storage-base');

class MyStorage extends StorageBase {
    // Resolve to true if a file already exists at targetDir/fileName.
    exists(fileName, targetDir) { /* ... */ }
    // Persist `file` and resolve to the public URL/path it's served at.
    save(file, targetDir) { /* ... */ }
    // Return an Express middleware that serves stored files.
    serve() { /* ... */ }
    // Remove a stored file.
    delete(fileName, targetDir) { /* ... */ }
    // Resolve to a Buffer of the file at options.path.
    read(options) { /* ... */ }
}

module.exports = MyStorage;
```

The base class supplies these helpers:

- `getTargetDir(baseDir)` returns a `YYYY/MM` path, optionally inside `baseDir`.
- `getSanitizedFileName(fileName)` replaces unsupported filename characters with `-`.
- `getUniqueFileName(file, targetDir)` and `generateUnique(dir, name, ext, i)`
  call `this.exists(...)` until they find a free filename (`exists` must return
  a `Promise<boolean>`).

### Installing and activating

Place the adapter at `content/adapters/storage/MyStorage/index.js` and activate
it in your Ghost config. Storage has three separate feature keys — `active`
(images), `media`, and `files` — and the block named after the adapter is
passed to its constructor:

```json
{
    "storage": {
        "active": "MyStorage",
        "MyStorage": {}
    }
}
```

## Develop

This is a workspace package in the Ghost monorepo. From the repo root:

```bash
pnpm --filter ghost-storage-base build   # compile to build/ with tsc (ESM)
pnpm --filter ghost-storage-base test    # type-check + unit tests
```

This package is ESM-only and compiled with `tsc` (`module: nodenext`). Relative
imports in `src/` must carry an explicit extension; write the real `.ts` one —
`import {x} from './x.ts'` — and `tsc` rewrites it to `.js` on emit
(`rewriteRelativeImportExtensions`).

# Copyright & License

Copyright (c) 2013-2026 Ghost Foundation - Released under the [MIT license](LICENSE). Ghost and the Ghost Logo are trademarks of Ghost Foundation Ltd. Please see our [trademark policy](https://ghost.org/trademark/) for info on acceptable usage.

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