@ionleahu/azure-storage-helper
v1.1.4
Published
Reusable Azure File Share CRUD provider for Node.js microservices
Maintainers
Readme
@ionleahu/azure-storage-helper
Reusable, typed Azure File Share CRUD provider for Node.js services.
Install
npm install @ionleahu/azure-storage-helper @azure/storage-file-share @azure/identityAuth Configuration
Use one of these approaches:
- Connection string:
AZURE_STORAGE_CONNECTION_STRINGAZURE_STORAGE_SHARE
- Managed identity (DefaultAzureCredential):
AZURE_STORAGE_ACCOUNT_NAMEAZURE_STORAGE_SHARE
Quick Start
import { AzureStorageProvider } from "@ionleahu/azure-storage-helper";
const storage = new AzureStorageProvider({
shareName: process.env.AZURE_STORAGE_SHARE!,
defaultDirectoryPath: "uploads",
connectionString: process.env.AZURE_STORAGE_CONNECTION_STRING!
});
await storage.createFile({
filePath: "sample.json",
data: JSON.stringify({ ok: true }),
contentType: "application/json"
});
const file = await storage.readFile({ filePath: "sample.json", mode: "buffer" });
await storage.updateFile({
filePath: "sample.json",
data: JSON.stringify({ ok: true, updated: true }),
mode: "overwrite",
contentType: "application/json"
});
await storage.deleteFile({ filePath: "sample.json", ifExists: true });
await storage.deleteFolder({ folderPath: "users/user-123", ifExists: true });API
createFile(request)readFile(request)updateFile(request)deleteFile(request)deleteFolder(request)(recursive: removes all nested folders/files)
Typed request/response models are exported from the package entrypoint.
License
MIT
