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

nodejs-common-utils

v1.0.2

Published

A comprehensive utility library for NodeJS applications providing geolocation, currency conversion, and AWS S3 file management functions.

Readme

common-utils

A comprehensive utility library for NodeJS applications providing geolocation, currency conversion, and AWS S3 file management functions.

This library simplifies common tasks such as retrieving location information from IP addresses, converting prices between currencies, ensuring directory existence for file operations, and managing files in AWS S3. It is designed to be easy to use and integrate into your NodeJS projects, making it a valuable tool for developers working with geolocation, currency data, and cloud storage.

Installation

npm install nodejs-common-utils

Features

  • Geolocation: Get location information from IP addresses
  • Currency Conversion: Convert prices between different currencies
  • File System Utilities: Ensure directory existence for safe file operations
  • AWS S3 Operations:
    • Upload files to S3
    • Copy S3 directories
    • Delete S3 files and directories
    • Get file and image object information

Usage

Geolocation and Currency Functions

const { getLocationInfo, getCurrencyByIP, getExchangeRate, convertPrice } = require('nodejs-common-utils');

// Get location info for an IP address
const locationInfo = await getLocationInfo('8.8.8.8');

// Get currency code for an IP address
const currency = await getCurrencyByIP('8.8.8.8');

// Get exchange rate from USD to EUR
const rate = await getExchangeRate('USD', 'EUR');

// Convert price using exchange rate
const priceInEUR = convertPrice(100, 0.85); // 85.00

File System Utilities

const { ensureDirectoryExistence } = require('nodejs-common-utils');

// Make sure directory exists before writing a file
const filePath = '/path/to/your/file.txt';
ensureDirectoryExistence(filePath);
fs.writeFileSync(filePath, 'Your content here');

S3 Utilities

const AWS = require('aws-sdk');
const { 
  uploadS3Files, 
  emptyS3Directory, 
  copyS3Directory, 
  deleteS3Files,
  getS3ImageObject,
  getS3FileObject
} = require('nodejs-common-utils');

// Configure AWS S3 client
const s3Client = new AWS.S3({
  accessKeyId: 'YOUR_ACCESS_KEY',
  secretAccessKey: 'YOUR_SECRET_KEY',
  region: 'YOUR_REGION'
});

// Example: Upload files to S3
const files = await uploadS3Files(req, {
  s3Client,
  bucketName: 'your-bucket-name',
  key: 'file', // Form field name
  s3KeyPrefix: 'uploads/',
  file_types: ['image/jpeg', 'image/png', 'application/pdf'],
  extract_pdf_text: true
});

// Example: Copy S3 directory
await copyS3Directory({
  s3Client,
  bucketName: 'your-bucket-name',
  from_prefix: 'source-folder/',
  to_prefix: 'destination-folder/',
  only_direct: false // Whether to copy only direct children
});

// Example: Empty S3 directory
await emptyS3Directory(s3Client, 'your-bucket-name', 'folder-to-empty/');

// Example: Delete specific S3 files
await deleteS3Files(
  ['path/to/file1.jpg', 'path/to/file2.pdf'], 
  'path/to/', 
  { s3Client, bucketName: 'your-bucket-name' }
);

Dependencies

  • axios - For HTTP requests
  • moment - For date handling
  • short-unique-id - For generating unique identifiers
  • image-size - For getting image dimensions
  • pdf-parse - For extracting text from PDF files
  • file-type - For detecting file types from buffers

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

  1. Fork the repository
  2. Create your feature branch (git checkout -b feature/amazing-feature)
  3. Commit your changes (git commit -m 'Add some amazing feature')
  4. Push to the branch (git push origin feature/amazing-feature)
  5. Open a Pull Request

License

This project is licensed under the MIT License - see the LICENSE file for details.

Author

Biswarup Mandal

Repository

GitHub

Issues

Report issues