npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2025 – Pkg Stats / Ryan Hefner

@hudoro/upload-file

v0.0.1-beta.33

Published

Backend bundling for express

Readme

Hudoro Upload File

Hudoro Upload File is a package that helps the file upload process easily and efficiently. Supports various file types, size validation, and flexible file extensions. Suitable for use on backend and frontend that require practical file upload features.

Package instalation

Instal package using pnpm

  pnpm add @hudoro/upload-file

Instal package using yarn

  yarn add @hudoro/upload-file

Instal package using npm

  npm i @hudoro/upload-file

Configuration

Configure the Google Cloud Storage client with your credentials:

import { gcsConfig } from "@hudoro/upload-file";
import { Storage } from "@google-cloud/storage";

const storage = new Storage({
  keyFilename: "serviceaccount.json",
  projectId: "your-project-id",
});

export const gcs = gcsConfig({
  bucketName: "your-bucket",
  gcsUrl: "https://storage.googleapis.com",
  gcsFolder: "your-folder",
  storage,
});

Usage

The package provides several functions for managing files in Google Cloud Storage:

Get File Size Retrieve the size of a file:

// getFileSize(path)
const size = await gcs.getFileSize("/documents/file.pdf");

Upload File Upload a file to Google Cloud Storage:

// uploadFile(buffer, mimetype)
const file = req.file;
const uploadResult = await gcs.uploadFile(file.buffer, file.mimetype);

Copy Object Copy a file from one location to another:

// copyObject(from, to)
const copyResult = await gcs.copyObject("/images/profile.png", "/users/images/profile.png");

Remove Object Delete a file from storage:

// removeObject(path)
const removeResult = await gcs.removeObject("/images/profile.png");

Get Public URL Generate a public URL for accessing a file:

// getPublicUrl(fileName)
const url = await gcs.getPublicUrl("/images/profile.png");

Get File Buffer Retrieve a file as a buffer:

// getFileBuffer(fileName)
const buffer = await gcs.getFileBuffer("/images/profile.png");

Get File Stream Get a readable stream of a file:

// getFileStream(fileName)
const stream = await gcs.getFileStream("/images/profile.png");

Check if Object Exists Verify if a file exists in storage:

// isObjectExist(fileName)
const exists = await gcs.isObjectExist("/images/profile.png");

Get File Metadata Retrieve metadata for a file:

// getFileMetadata(fileName)
const metadata = await gcs.getFileMetadata("/images/profile.png");

Complete Example

javascriptimport { gcsConfig } from "@hudoro/upload-file";
import { Storage } from "@google-cloud/storage";

const storage = new Storage({
  keyFilename: "serviceaccount.json",
  projectId: "your-project-id",
});

export const gcs = gcsConfig({
  bucketName: "your-bucket",
  gcsUrl: "https://storage.googleapis.com",
  gcsFolder: "your-folder",
  storage,
});

async function handleFileOperations() {
  try {
    // Upload a file
    const fileBuffer = Buffer.from("Hello, World!");
    const uploadResult = await gcs.uploadFile(fileBuffer, "text/plain");
    console.log("Uploaded:", uploadResult);
    
    // Get file size
    const size = await gcs.getFileSize("/documents/file.txt");
    console.log("File size:", size);
    
    // Generate public URL
    const url = await gcs.getPublicUrl("/documents/file.txt");
    console.log("Public URL:", url);
    
    // Check if file exists
    const exists = await gcs.isObjectExist("/documents/file.txt");
    console.log("File exists:", exists);
    
    // Copy file to another location
    await gcs.copyObject("/documents/file.txt", "/archive/file.txt");
    console.log("File copied successfully");
    
    // Delete original file
    await gcs.removeObject("/documents/file.txt");
    console.log("File removed successfully");
  } catch (error) {
    console.error("Error:", error);
  }
}

Error Handling

All functions include proper error handling. It's recommended to use try/catch blocks when calling these functions to handle any potential errors.

Parameter for gcs config

Props that you can pass to GCS Config

| Prop Name | Value | required | | :------------------- | :------------------------------------------ | :------- | | storage | Storage | true | | bucketName | string | true | | gcsUrl | string | true | | gcsFolder | string | true |