2021-07-11 15:42:56 +02:00
---
id: plugin-storage
2022-12-25 18:48:18 +01:00
title: 'Storage Plugin'
2021-07-11 15:42:56 +02:00
---
2023-02-18 15:42:19 +01:00
## What's a Storage Plugin? {#whats-a-storage-plugin}
2021-07-11 15:42:56 +02:00
2021-10-19 08:57:56 +02:00
Verdaccio by default uses a file system storage plugin [local-storage ](https://github.com/verdaccio/verdaccio/tree/master/packages/plugins/local-storage ). The default storage can be easily replaced, either using a community plugin or creating one by your own.
2021-07-11 15:42:56 +02:00
2021-07-27 21:52:49 +02:00
### API {#api}
2021-07-11 15:42:56 +02:00
Storage plugins are composed of two objects, the `IPluginStorage<T>` and the `IPackageStorage` .
2022-12-25 18:48:18 +01:00
- The `IPluginStorage` object handle the local database for private packages.
2021-07-11 15:42:56 +02:00
```typescript
2022-12-25 18:48:18 +01:00
interface IPluginStorage< T > extends IPlugin< T > , ITokenActions {
logger: Logger;
config: T & Config;
add(name: string, callback: Callback): void;
remove(name: string, callback: Callback): void;
get(callback: Callback): void;
getSecret(): Promise< string > ;
setSecret(secret: string): Promise< any > ;
getPackageStorage(packageInfo: string): IPackageStorage;
search(
onPackage: onSearchPackage,
onEnd: onEndSearchPackage,
validateName: onValidatePackage
): void;
}
2021-07-11 15:42:56 +02:00
```
2022-12-25 18:48:18 +01:00
- The `IPackageStorage` is an object that is created by each request that handles the I/O actions for the metadata and tarballs.
2021-07-11 15:42:56 +02:00
```typescript
interface IPackageStorage {
logger: Logger;
writeTarball(pkgName: string): IUploadTarball;
readTarball(pkgName: string): IReadTarball;
readPackage(fileName: string, callback: ReadPackageCallback): void;
createPackage(pkgName: string, value: Package, cb: CallbackAction): void;
deletePackage(fileName: string, callback: CallbackAction): void;
removePackage(callback: CallbackAction): void;
updatePackage(
pkgFileName: string,
updateHandler: StorageUpdateCallback,
onWrite: StorageWriteCallback,
transformPackage: PackageTransformer,
onEnd: CallbackAction
): void;
savePackage(fileName: string, json: Package, callback: CallbackAction): void;
}
```
2021-07-27 21:52:49 +02:00
## Generate an middleware plugin {#generate-an-middleware-plugin}
2021-07-11 15:42:56 +02:00
For detailed info check our [plugin generator page ](plugin-generator ). Run the `yo` command in your terminal and follow the steps.
```
➜ yo verdaccio-plugin
Just found a `.yo-rc.json` in a parent directory.
Setting the project root at: /Users/user/verdaccio_yo_generator
_-----_ ╭──────────────────────────╮
| | │ Welcome to │
|--(o)--| │ generator-verdaccio-plug │
`---------´ │ in plugin generator! │
( _´ U`_ ) ╰──────────────────────────╯
/___A___\ /
| ~ |
__ '.___.'__
´ ` |° ´ Y `
? What is the name of your plugin? custom-endpoint
? Select Language typescript
? What kind of plugin you want to create? storage
? Please, describe your plugin awesome storage plugin
? GitHub username or organization myusername
? Author's Name Juan Picado
? Author's Email jotadeveloper@gmail.com
? Key your keywords (comma to split) verdaccio,plugin,storage,awesome,verdaccio-plugin
create verdaccio-plugin-storage-package-database/package.json
create verdaccio-plugin-storage-package-database/.gitignore
create verdaccio-plugin-storage-package-database/.npmignore
create verdaccio-plugin-storage-package-database/jest.config.js
create verdaccio-plugin-storage-package-database/.babelrc
create verdaccio-plugin-storage-package-database/.travis.yml
create verdaccio-plugin-storage-package-database/README.md
create verdaccio-plugin-storage-package-database/.eslintrc
create verdaccio-plugin-storage-package-database/.eslintignore
create verdaccio-plugin-storage-package-database/src/PackageStorage.ts
create verdaccio-plugin-storage-package-database/src/index.ts
create verdaccio-plugin-storage-package-database/src/plugin.ts
create verdaccio-plugin-storage-package-database/index.ts
create verdaccio-plugin-storage-package-database/tsconfig.json
create verdaccio-plugin-storage-package-database/types/index.ts
create verdaccio-plugin-storage-package-database/.editorconfig
I'm all done. Running npm install for you to install the required dependencies. If this fails, try running the command yourself.
⸨ ░░░░░░░░░░░░░░░░░⸩ ⠋ fetchMetadata: sill pacote range manifest for @babel/plugin -syntax-jsx@^7.7.4 fetc
```
2021-07-27 21:52:49 +02:00
### List Community Storage Plugins {#list-community-storage-plugins}
2021-07-11 15:42:56 +02:00
The following list of plugins are implementing the Storage API and might be used them as example.
2022-12-25 18:48:18 +01:00
- [verdaccio-memory ](https://github.com/verdaccio/verdaccio-memory ) Storage plugin to host packages in Memory
- [verdaccio-s3-storage ](https://github.com/remitly/verdaccio-s3-storage ) Storage plugin to host packages **Amazon S3**
2023-03-04 12:26:48 +01:00
- [verdaccio-aws-s3-storage ](https://github.com/verdaccio/monorepo/tree/verdaccio-aws-s3-storage%4010.3.0/plugins/aws-s3-storage ) Storage plugin to host packages **Amazon S3** (maintained by Verdaccio core team)
2022-12-25 18:48:18 +01:00
- [verdaccio-google-cloud ](https://github.com/verdaccio/verdaccio-google-cloud ) Storage plugin to host packages **Google Cloud Storage**
- [verdaccio-minio ](https://github.com/barolab/verdaccio-minio ) A verdaccio plugin for storing data in Minio
2023-03-05 07:57:12 +01:00
- [verdaccio-offline-storage ](https://github.com/g3ngar/verdaccio-offline-storage ) local-storage plugin BUT with locally available packages as first class citizens.