fikri-backend
v0.0.1-beta.30
Published
Backend bundling for express
Readme
Hudoro Backend
Hudoro Backend is a practical and customizable express js backend bundling library for backend projects, designed for simplicity and compliance with backend standards.
Package instalation
Instal package using pnpm
pnpm add @hudoro/backendInstal package using yarn
yarn add @hudoro/backendInstal package using npm
npm i @hudoro/backendUsage/Examples Config Upload Asset to Google Cloud Storage
import { gcsConfig, uploadStorage } from "../src";
export const gcs = gcsConfig({
bucketName: "your-bucket",
options: {
keyFilename: "your-key-file-name",
projectId: "your-project-id",
},
});
export const upload = uploadStorage({
bucket: gcs.bucket,
gcsUrl: "your-gcs-url",
gcsFolder: "your-folder",
bucketName: gcs.bucketName,
});
export const yourService = async() => {
const { getFileSize, uploadFile, copyObject, removeObject, getPublicUrl, getFileBuffer, getFileStream, isObjectExist, getFileMetadata } = upload;
// Get Size
// getFileSize(path)
const size = getFileSize("/documents/file.pdf");
// Upload File
// uploadFile(buffer, mimetype)
const file = req.file
const size = uploadFile(file, file.mimetype);
// Copy Object File
// copyObject(from, to)
const copy = copyObject("/images/profile.png", "/users/images/profile.png");
// Remove Object File
// removeObject(path)
const remove = removeObject("/images/profile.png");
// Public URL
// getPublicUrl(fileNames)
const url = getPublicUrl("/images/profile.png");
// File Buffer
// getFileBuffer(fileNames)
const buffer = getFileBuffer("/images/profile.png");
// File Stream
// getFileStream(fileNames)
const stream = getFileStream("/images/profile.png");
// Object Exist
// isObjectExist(fileNames)
const stream = isObjectExist("/images/profile.png");
// File Metadata
// getFileMetadata(fileNames)
const stream = getFileMetadata("/images/profile.png");
}
Parameter for gcs config
Props that you can pass to GCS Config
| Prop Name | Value | required | | :------------------- | :------------------------------------------ | :------- | | options | StorageOptions | false | | bucketName | string | true |
Parameter for upload storage
Props that you can pass to Upload Storage
| Prop Name | Value | required | | :------------------- | :------------------------------------------ | :------- | | bucket | Bucket | true | | gcsUrl | string | true | | gcsFolder | string | true |
