npm-s3

S3-cached npm installs keyed by a unique hash of package.json

Usage no npm install needed!

<script type="module">
  import npmS3 from 'https://cdn.skypack.dev/npm-s3';
</script>

README

npm-s3

npm version Build Status Coverage Status

npm-s3 is a lightweight tool to cache node_modules from npm install to S3. On fresh installs, the node_modules directory is compressed into a tarball and uploaded to S3 keyed by a unique hash of the project's package.json file, ensuring that stale caches are not used when your project's dependencies change.

This significantly reduces the time for npm install on subsequent installs. This cached module installation workflow is especially useful for CI builds, where a fresh environment is prepared on every build.

npm-s3 supports specifying a custom S3 URL, so that you can use any private server that implements the S3 API like Minio.

Installation and Configuration

Get the CLI:

$ npm install -g npm-s3

npm-s3 can be invoked in any project directory with package.json. Specify the S3 URL, access key, and secret key as environment variables:

$ S3_URL=s3.yourserver.com ACCESS_KEY=access-key SECRET_KEY=secret-key npm-s3

You may alternatively save these values in ~/.npms3rc as

s3_url = s3.yourserver.com
access_key = access-key
secret_key = secret-key

By default, npm-s3 will cache tarballs to the bucket npm-cache. You can specify an alternate bucket with the BUCKET environment variable or bucket key in the config file.

Then, you can just invoke npm-s3.

$ npm-s3

Behavior

npm-s3 checks if you have a node_modules in your current directory.

  • If you do:
    • npm install
    • Check if a cache exists for the current package.json
      • If not, npm-s3 uploads a cache
  • If you don't:
    • npm-s3 checks if a cache exists for the current package.json
      • If you do, npm-s3 downloads the cache
      • If not:
        • npm install
        • Upload a cache