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 🙏

© 2024 – Pkg Stats / Ryan Hefner

http-to-s3

v2.0.8

Published

A utility to stream http requests to a file on S3

Downloads

16

Readme

HTTP to S3

This module streams a HTTP response to an S3 bucket. Both the HTTP response and the S3 upload are implemented using streams allowing large responses to be retrieved without having to worry about memory / disk space limitations.

Installation

npm install --save http-to-s3

Usage

Basic usage

const HttpToS3 = require("http-to-s3");
const httpS3Client = new HttpToS3();

const options = {
  s3: {
    Bucket: "sample-bucket",
    Key: "path/to/file.html"
  }
};
// Defaults to GET request
const uploadResult = await httpS3Client.get("http://example.com", options)

Advanced examples:

Post a body to the URL, stream the results to S3, and log upload progress

const HttpToS3 = require("http-to-s3");
const httpS3Client = new HttpToS3();

const postData = JSON.stringify({ test: true });

const options = {
  request:{
    headers: {
    'Content-Type': 'application/json',
    'Content-Length': Buffer.byteLength(postData)
    }
  }
  s3: {
    Bucket: "sample-bucket",
    Key: "path/to/file.html"
  },
  upload:{
    uploadProgress: (progress) => {
      console.log(`Uploaded ${progress.loaded} of ${progress.total} for ${progress.key}`)
    }
  }
};

const uploadResult = await httpS3Client.post("http://google.com/upload", options, postData)

Constructor details

new HttpToS3(options = {}) ⇒ Object

The constructor takes an options object with the following parameters:

  • s3 -- < S3 Client > -- an optional instantiated S3 client. See the AWS credentials section for an example.
  • s3Region -- string -- If provided and an S3 client isn't provided, a new client will be created with this as the default region
  • throwFailures -- boolean -- If set to true, the client will throw an error if the server returns a non-2xx response, otherwise an object is returned. Default: false

It returns an object will the following methods:

httpS3Client.request(url, options, body) ⇒ Object

  • url -- string -- a string URL that can be parsed by the Node URL Class

  • options -- object -- an object with two keys, a set of request options and and S3 options

    • request -- an options object that will be fed into the HTTP.request.
      • Note, protocol, host, path, and port will be set automatically from the URL. If method is not set, it will be defaulted to GET
    • s3 -- object -- an options object that will be fed into the S3 upload method
      • Simplest usage is to just provide Bucket and Key
    • upload -- object
      • uploadProgress -- function (progress) -- an optional function that will receive httpUploadProgress events from the S3 ManagedUpload
  • body -- string / Buffer -- An optional string or buffer to be written to the request body

httpS3Client.post(url, options, body) ⇒ Object

The post method is largely identical to the request method, however it will default the method on the request to POST

httpS3Client.get(url, options) ⇒ Object

The post method is largely identical to the request method, however it will default the method on the request to GET

AWS Credentials

This module uses the Node AWS SDK, therefore it will look for credentials in the places specified by the AWS SDK.

If you need to specify your credentials manually, you can provide a pre-configured AWS S3 Client to the constructor.

const AWS = require('aws-sdk');
const HttpToS3 = require('http-to-s3');
const S3Client = new AWS.S3({
  accessKeyId: <key id here>,
  accessKeyId: <secret key here>,
});

const httpS3Client = new HttpToS3({ s3: S3Client });

Tests

Test specs live side-by-side with the file they're testing, following the standard Jest pattern file.test.js.

To run tests: npm test

build

To build the dist files: npm run build