@arikajs/storage is the filesystem abstraction layer for the ArikaJS framework.
It provides a clean, unified API to work with local and cloud-based storage systems using interchangeable drivers, designed for maximum developer experience but designed for Node.js and TypeScript.
This package allows ArikaJS applications to interact with files without caring where or how they are stored.
- Multiple storage disks: Configure different storage locations
- Driver-based filesystem architecture: Pluggable storage backends
- Storage Extensibility: Register custom drivers via
extend() - Middleware pipelines: Intercept operations via
disk().middleware() - Local filesystem driver: Built-in support for local file storage (v1)
- Unified file API:
put,get,delete,exists,url,copy,move - File mutation API:
append,prepend - Buffer, string, and stream support: Flexible content handling
- Configuration-based disk resolution: Easy setup via config files
- TypeScript-first: Full type safety with JavaScript compatibility
- Designed for cloud drivers: Ready for S3, GCS, Azure (S3 shipped)
npm install @arikajs/storage
# or
yarn add @arikajs/storage
# or
pnpm add @arikajs/storageimport { Storage } from '@arikajs/storage';
// Write a file
await Storage.put('files/example.txt', 'Hello Arika');
// Read a file
const content = await Storage.get('files/example.txt');
// Delete a file
await Storage.delete('files/example.txt');Arika Storage supports multiple disks, each backed by a driver.
// Use a specific disk
await Storage.disk('local').put('notes.txt', 'Hello');
// Check if file exists on a disk
const exists = await Storage.disk('public').exists('image.png');Storage disks are defined in your application configuration:
export default {
default: 'local',
disks: {
local: {
driver: 'local',
root: './storage/app'
},
public: {
driver: 'local',
root: './storage/public',
url: '/storage'
}
}
};| Driver | Status |
|---|---|
| Local filesystem | β Supported |
| Amazon S3 | β Supported |
| Google Cloud Storage | β Supported |
| Azure Blob Storage | β Supported |
Write contents to a file.
await Storage.put('file.txt', 'content');Read file contents.
const content = await Storage.get('file.txt');Throws FileNotFoundException if the file does not exist.
Check if a file exists.
const exists = await Storage.exists('file.txt');Delete a file.
await Storage.delete('file.txt');Copy a file to a new location.
await Storage.copy('file.txt', 'backup.txt');Move a file to a new location.
await Storage.move('file.txt', 'archive.txt');Append contents to a file.
await Storage.append('log.txt', 'New log entry');Prepend contents to a file.
await Storage.prepend('log.txt', 'First entry');Get the public URL for a file.
const url = Storage.url('image.png');Returns a public URL if supported by the disk.
storage/
βββ src/
β βββ Contracts
β β βββ Filesystem.ts
β βββ Drivers
β β βββ AzureDriver.ts
β β βββ GCSDriver.ts
β β βββ LocalDriver.ts
β β βββ S3Driver.ts
β βββ Exceptions
β β βββ FileNotFoundException.ts
β βββ Disk.ts
β βββ index.ts
β βββ StorageManager.ts
βββ tests/
βββ package.json
βββ tsconfig.json
βββ README.md
You can create your own storage driver:
import { Filesystem } from '@arikajs/storage';
class CustomDriver implements Filesystem {
async put(path: string, contents: string | Buffer): Promise<void> {
// Implementation
}
async get(path: string): Promise<Buffer> {
// Implementation
}
async delete(path: string): Promise<void> {
// Implementation
}
async exists(path: string): Promise<boolean> {
// Implementation
}
url(path: string): string {
// Implementation
}
}Register it inside StorageManager using the extend() method:
storage.extend('custom', (config) => new CustomDriver(config));You can attach disk-level middleware to intercept any storage operations (e.g., logging every write, encrypting payloads on .put(), etc.).
storage.disk('local').middleware(async (data, next) => {
if (data.operation === 'put') {
console.log(`Writing file: ${data.path}`);
// Optionally modify payload before saving!
// data.contents = encrypt(data.contents);
}
return await next(data);
});@arikajs/storage integrates seamlessly with:
@arikajs/authβ User uploads@arikajs/mailβ Attachments@arikajs/loggingβ File logs@arikajs/queueβ Temporary files@arikajs/viewβ Asset handling
The storage layer is fully testable by mocking drivers or using temporary disks.
- S3 driver
- GCS driver
- Azure Blob driver
- Streaming API
- Temporary signed URLs
- Disk-level middleware
- File metadata support
@arikajs/storage is open-source software licensed under the MIT License.
"Your application should care about files, not filesystems."