{"id":20774045,"url":"https://github.com/secjs/storage","last_synced_at":"2026-04-18T00:32:02.490Z","repository":{"id":43353176,"uuid":"432780691","full_name":"SecJS/Storage","owner":"SecJS","description":"🗃️ Handle your application files in Node.js","archived":false,"fork":false,"pushed_at":"2022-03-06T13:36:02.000Z","size":634,"stargazers_count":3,"open_issues_count":2,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2025-10-14T12:58:22.275Z","etag":null,"topics":["cloud","disk","filesystem","gcs","nodejs","s3","storage"],"latest_commit_sha":null,"homepage":"","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/SecJS.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":"CONTRIBUTING.md","funding":".github/FUNDING.yml","license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null},"funding":{"open_collective":"secjs"}},"created_at":"2021-11-28T17:35:42.000Z","updated_at":"2022-01-07T17:25:31.000Z","dependencies_parsed_at":"2022-09-23T11:04:16.006Z","dependency_job_id":null,"html_url":"https://github.com/SecJS/Storage","commit_stats":null,"previous_names":[],"tags_count":5,"template":false,"template_full_name":null,"purl":"pkg:github/SecJS/Storage","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SecJS%2FStorage","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SecJS%2FStorage/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SecJS%2FStorage/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SecJS%2FStorage/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/SecJS","download_url":"https://codeload.github.com/SecJS/Storage/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SecJS%2FStorage/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":31951285,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-04-17T17:29:20.459Z","status":"ssl_error","status_checked_at":"2026-04-17T17:28:47.801Z","response_time":62,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.6:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["cloud","disk","filesystem","gcs","nodejs","s3","storage"],"created_at":"2024-11-17T12:28:11.474Z","updated_at":"2026-04-18T00:32:02.455Z","avatar_url":"https://github.com/SecJS.png","language":"TypeScript","funding_links":["https://opencollective.com/secjs","https://www.buymeacoffee.com/secjs"],"categories":[],"sub_categories":[],"readme":"# Storage 🗃️\n\n\u003e Handle your application files in Node.js\n\n[![GitHub followers](https://img.shields.io/github/followers/secjs.svg?style=social\u0026label=Follow\u0026maxAge=2592000)](https://github.com/secjs?tab=followers)\n[![GitHub stars](https://img.shields.io/github/stars/secjs/storage.svg?style=social\u0026label=Star\u0026maxAge=2592000)](https://github.com/secjs/storage/stargazers/)\n\n\u003cp\u003e\n    \u003ca href=\"https://www.buymeacoffee.com/secjs\" target=\"_blank\"\u003e\u003cimg src=\"https://www.buymeacoffee.com/assets/img/custom_images/orange_img.png\" alt=\"Buy Me A Coffee\" style=\"height: 41px !important;width: 174px !important;box-shadow: 0px 3px 2px 0px rgba(190, 190, 190, 0.5) !important;-webkit-box-shadow: 0px 3px 2px 0px rgba(190, 190, 190, 0.5) !important;\" \u003e\u003c/a\u003e\n\u003c/p\u003e\n\n\u003cp\u003e\n  \u003cimg alt=\"GitHub language count\" src=\"https://img.shields.io/github/languages/count/secjs/storage?style=for-the-badge\u0026logo=appveyor\"\u003e\n\n  \u003cimg alt=\"Repository size\" src=\"https://img.shields.io/github/repo-size/secjs/storage?style=for-the-badge\u0026logo=appveyor\"\u003e\n\n  \u003cimg alt=\"License\" src=\"https://img.shields.io/badge/license-MIT-brightgreen?style=for-the-badge\u0026logo=appveyor\"\u003e\n\n  \u003cimg alt=\"Commitizen\" src=\"https://img.shields.io/badge/commitizen-friendly-brightgreen?style=for-the-badge\u0026logo=appveyor\"\u003e\n\u003c/p\u003e\n\nThe intention behind this repository is to always maintain a `Storage` class to manipulate files using any driver.\n\n\u003cimg src=\".github/storage.png\" width=\"200px\" align=\"right\" hspace=\"30px\" vspace=\"100px\"\u003e\n\n## Installation\n\n\u003e To use the high potential from this package you need to install first this other packages from SecJS,\n\u003e it keeps as dev dependency because one day `@secjs/core` will install everything once.\n\n```bash\nnpm install @secjs/env @secjs/utils @secjs/contracts @secjs/exceptions\n```\n\n\u003e Then you can install the package using:\n\n```bash\nnpm install @secjs/storage\n```\n\n## Usage\n\n### Config filesystem template\n\n\u003e First you need to create the configuration file *filesystem* in the config folder on project root path. Is extremely important to use export default in these configurations.\n\n```ts\nimport { Env } from '@secjs/env'\nimport { Path } from '@secjs/utils'\n\nexport default {\n  /*\n  |--------------------------------------------------------------------------\n  | Default Filesystem Disk\n  |--------------------------------------------------------------------------\n  |\n  | Here you may specify the default filesystem disk that should be used\n  | by the framework. The \"local\" disk, as well as a variety of cloud\n  | based disks are available to your application.\n  |\n  */\n\n  default: Env('FILESYSTEM_DISK', 'local'),\n\n  /*\n  |--------------------------------------------------------------------------\n  | Filesystem Disks\n  |--------------------------------------------------------------------------\n  |\n  | Here you may configure as many filesystem \"disks\" as you wish, and you\n  | may even configure multiple disks of the same driver. Defaults have\n  | been setup for each driver as an example of the required options.\n  |\n  */\n\n  disks: {\n    local: {\n      driver: 'local',\n      root: Path.noBuild().storage('app'),\n      url: `${Env('APP_URL', '')}/storage`,\n    },\n    public: {\n      driver: 'local',\n      root: Path.noBuild().storage('app/public'),\n      url: `${Env('APP_URL', '')}/storage/public`,\n    },\n    s3: {\n      driver: 's3',\n      key: Env('AWS_KEY', ''),\n      secret: Env('AWS_SECRET', ''),\n      region: Env('AWS_REGION', ''),\n      bucket: Env('AWS_BUCKET', ''),\n      endpoint: Env('AWS_ENDPOINT', '')\n    },\n    gcs: {\n      driver: 'gcs',\n      project: Env('GCS_PROJECT', ''),\n      secret: Env('GCS_SECRET', ''),\n      bucket: Env('GCS_BUCKET', ''),\n      endpoint: Env('GCS_ENDPOINT', ''),\n    },\n  },\n}\n```\n\n### Storage\n\n\u003e With the config/filesystem file created you can use Storage class to start storing your files.\n\n```ts\nimport { Storage } from '@secjs/storage'\n\nconst storage = new Storage()\n\n// Storage class will always use the default value set in config/filesystem to store the files, in this case, local.\nawait storage.put('file.txt', Buffer.from('hello world!'))\n// The file will be saved in the root storage/app/file.txt, according to config/filesystem.\n\n// You can use putFile method to create a file \"without name\", an unique id will be generated for him.\nconst path = await storage.putFile('folder', 'txt', Buffer.from('hello world!')) // returns the path -\u003e folder/DASdsakdjas912831jhdasnm.txt\n// The file will be saved in the root storage/app/folder/DASdsakdjas912831jhdasnm.txt, according to config/filesystem.\n```\n\n```ts\n// You can use exists and missing too\nconsole.log(await storage.exists('folder/DASdsakdjas912831jhdasnm.txt')) // true\nconsole.log(await storage.missing('folder/DASdsakdjas912831jhdasnm.txt')) // false\n\n// You can get only the content of the file in Buffer using get\nawait storage.get('folder/DASdsakdjas912831jhdasnm.txt') // Buffer\u003c6c 6c 6c 6c...\u003e\n```\n\n```ts\n// You can generate an url and a temporaryUrl to your file based on config/filesystem.\nawait storage.url('folder/DASdsakdjas912831jhdasnm.txt') // https://cdn.secjs.io/storage/folder/DASdsakdjas912831jhdasnm.txt\n// 10 minutes = 600000ms\nawait storage.temporaryUrl('folder/DASdsakdjas912831jhdasnm.txt', 600000) // https://cdn.secjs.io/storage/folder/temp/30219310391sadlksa12039.txt\n```\n\n```ts\n// You can delete the file using delete\nconst force = true\n// You can use force to not throw exceptions if file does not exist\nawait storage.delete('folder/DASdsakdjas912831jhdasnm.txt', force)\n```\n\n```ts\n// You can use copy and move\n// In this case folder/DASdsakdjas912831jhdasnm.txt will still exists\nawait storage.copy('folder/DASdsakdjas912831jhdasnm.txt', 'folder/test/copy.txt')\n\n// In this case folder/DASdsakdjas912831jhdasnm.txt will be removed\nawait storage.move('folder/DASdsakdjas912831jhdasnm.txt', 'folder/test/move.txt')\n```\n\n### Subscribing configs of disks in runtime\n\n\u003e You can subscribe the disks configs in runtime using in Storage constructor or disk method\n\n```ts\n// Using disk method approach\n// File created on storage/newAppFolder/file.txt\nstorage\n  .disk('local', { root: Path.noBuild().storage('newAppFolder') })\n  .put('file.txt', Buffer.from('Hello World'))\n\n// Using constructor method approach\nconst newStorage = new Storage({ root: Path.noBuild().storage('newAppFolder') })\n\n// File created on storage/newAppFolder/file2.txt\nnewStorage.put('file2.txt', Buffer.from('Hello World'))\n\n// You can reset configs using an empty object in the disk method\nstorage.disk('local', {}) // Clear the runtime configuration\n```\n\n### Using S3 or GCS disk\n\n\u003e You can use **s3** or **gcs** disk to make all this actions inside buckets\n\n```ts\n// Saves to S3\nstorage.disk('s3').put('folder/file.txt', Buffer.from('Hello world!'))\n// Saves to GCS\nstorage.disk('gcs').put('folder/file.txt', Buffer.from('Hello world!'))\n```\n\n### Extending disks and drivers\n\n\u003e Nowadays, @secjs/storage has only LocalDriver, S3Driver and GCSDriver support, but you can extend the drivers for Storage class if you implement DriverContract interface\n\n```ts\nimport { DriverContract } from '@secjs/storage'\n\nclass CustomDriver implements DriverContract {\n  private readonly _url: string\n  private readonly _root: string\n  \n  constructor(disk: string) {\n    this._url = Config.get(`filesystem.disks.${disk}.url`)\n    this._root = Config.get(`filesystem.disks.${disk}.root`)\n  }\n  \n  // all the methods implemented from DriverContract...\n}\n```\n\n\u003e Constructor is extremely important in your CustomDriver class, it's the constructor that \n\u003e will use the values from config/filesystem disks to manipulate your CustomDriver using \n\u003e `disk` method from storage. So if you are building a CustomDriver, and you want to use it,\n\u003e you can create a new disk inside config/filesystem disks or change the driver from an existing disk.\n\n```ts\n// extending disks\n// config/filesystem file\n\nexport default {\n  // default etc...\n  \n  disks: {\n    mydisk: {\n      driver: 'custom',\n      root: Path.storage('app/mydisk'),\n      url: `${Env('APP_URL', '')}/storage/mydisk`,\n    }\n    // ... other disks\n  }\n}\n```\n\n\u003e Build you new driver using build static method\n\n```ts\nconst name = 'custom'\nconst driver = CustomDriver\n\nStorage.build(name, driver)\n\nconsole.log(Storage.drivers) // ['s3', 'local', 'public', 'custom']\n```\n\n\u003e Now, if you have implemented your disk in config/filesystem, you can use him inside storage\n\n```ts\n// Will use CustomDriver to handle the file actions\nstorage.disk('mydisk').put('file.txt', Buffer.from('my custom driver'))\n```\n\n---\n\n## License\n\nMade with 🖤 by [jlenon7](https://github.com/jlenon7) :wave:\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsecjs%2Fstorage","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsecjs%2Fstorage","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsecjs%2Fstorage/lists"}