S3 Bucket manager for Node.js applications with Express integration.
Install the package via npm:
npm install mbkbucketimport { uploadFile, downloadFile, listfiles, getBucketConfig, packageJson, bucket } from 'mbkbucket';This imports the configured Express server instance:
import mbkbucket from 'mbkbucket';
// Access bucket router via: mbkbucket.bucketFor more granular control, import directly from submodules:
import { uploadFile } from 'mbkbucket/lib/s3';
import { packageJson } from 'mbkbucket/lib/config/index';
import bucketRouter from 'mbkbucket/lib/bucket';- All functions, objects, and variables exported from
lib/are re-exported at the package root for convenience. - TypeScript support with full type declarations (
index.d.ts) for IDE intellisense and type safety. - The default export is the configured Express
serverinstance; access thebucketrouter as a named export. - Supports Node.js 14.0.0 and higher with ES Modules.
- uploadFile() - Upload files to S3 bucket
- downloadFile() - Retrieve files from S3 bucket
- listfiles() - List contents of S3 bucket
- getBucketConfig() - Get current bucket configuration
- bucket - Express router with bucket management endpoints
For complete API documentation, refer to the TypeScript declarations in index.d.ts.
- Node.js >= 14.0.0
- AWS S3 credentials configured
- AWS SDK v3 compatible environment
The package validates both mbkbucketVar and BucketConnection at startup.
mbkautheVar.bucket is used as the default bucket.
Example:
mbkautheVar={"APP_NAME":"portal","loginRedirectURL":"/dashboard","bucket":"R2_Bucket"}Notes:
- If
APP_NAMEisportal, mbkbucket works from bucket root (noportal/folder prefix). - If
bucketis missing, mbkbucket falls back to the first bucket key inBucketConnection.
Use a JSON object where each key is a selectable connection name.
Example:
BucketConnection={"R2_Bucket":{"BUCKET_NAME":"my-r2-bucket","ACCESS_KEY_ID":"...","SECRET_ACCESS_KEY":"...","ENDPOINT":"https://<account-id>.r2.cloudflarestorage.com"},"S3_Bucket":{"BUCKET_NAME":"my-s3-bucket","ACCESS_KEY_ID":"...","SECRET_ACCESS_KEY":"...","ENDPOINT":"https://s3.ap-southeast-1.amazonaws.com"}}Required fields per bucket:
BUCKET_NAMEACCESS_KEY_IDSECRET_ACCESS_KEYENDPOINT
- Quoted inner object (invalid)
BucketConnection={"R2_Bucket":"{\"BUCKET_NAME\":\"...\"}"}- Correct inner object (valid)
BucketConnection={"R2_Bucket":{"BUCKET_NAME":"...","ACCESS_KEY_ID":"...","SECRET_ACCESS_KEY":"...","ENDPOINT":"https://..."}}- Admin page bucket selection:
/mbkbucket?bucket=R2_Bucket - Public view route
/mbkbucket/p_view/:key(*)always uses the default bucket frommbkautheVar.bucket.
Run tests:
npm testCurrent tests cover:
mbkbucketVarparsing/defaults/boolean normalizationBucketConnectionshape validation and required fields
For questions, issues, or contributions, please reach out:
- Website: mbktech.org/Support
- Email: [email protected] or [email protected]
- GitHub: MIbnEKhalid
Developed by Muhammad Bin Khalid
Part of MBK Tech Studio
Licensed under the GPL-2.0 License. See LICENSE file for details.