Socket
Book a DemoInstallSign in
Socket

@cortec/storage

Package Overview
Dependencies
Maintainers
1
Versions
8
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@cortec/storage

<description>

latest
Source
npmnpm
Version
1.5.2
Version published
Maintainers
1
Created
Source

@cortec/storage

Module Overview

The @cortec/storage package provides a unified interface for managing file storage backends. It currently supports disk-based storage and is designed to be extensible for other storage providers. The module allows you to configure multiple storage instances, each with its own directory and options, and access them by name.

Configuration Options

Where to put config: Place your storage config in config/default.yml (or your environment-specific config file).

Schema:

storage:
  uploads:
    dir: '/var/app/uploads'
    makeParent: true
  logs:
    dir: '/var/app/logs'
    makeParent: false

Field-by-field explanation:

  • storage: Root key for Storage config.
  • uploads, logs: Identity/name for each storage instance (can be any string).
  • dir: Directory path for storage. This is where files will be read/written.
  • makeParent: If true, parent directories will be created automatically if missing.

How config is loaded: The config is loaded automatically by the @cortec/config module and validated at runtime. Access it in code via:

import { Config } from '@cortec/config';
const storageConfig = Config.get('storage');

If config is missing or invalid, an error is thrown at startup.

Example YAML:

storage:
  uploads:
    dir: '/var/app/uploads'
    makeParent: true
  logs:
    dir: '/var/app/logs'
    makeParent: false

Example Usage

import Storage from '@cortec/storage';

// After context is loaded and storage module is initialized
const storage = new Storage();

// Get a storage instance by name
const uploadsStorage = storage.get('uploads');

// Use the storage instance (DiskStorage API)
await uploadsStorage.writeFile('example.txt', 'Hello, world!');
const content = await uploadsStorage.readFile('example.txt');
console.log(content); // "Hello, world!"

// Dispose all storage instances when shutting down
await storage.dispose();

API

storage.get(name: string): IBaseStorage

Returns the storage instance for the given name. Throws if not found.

DiskStorage Methods

The returned IBaseStorage instance supports typical file operations such as:

  • writeFile(filename: string, data: string | Buffer): Promise<void>
  • readFile(filename: string): Promise<string | Buffer>
  • deleteFile(filename: string): Promise<void>
  • dispose(): Promise<void>

Notes

  • Each storage instance is independent and configured via the main configuration file.
  • The module is designed to be extensible for cloud or remote storage providers in the future.

FAQs

Package last updated on 17 Oct 2025

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts