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 🙏

© 2026 – Pkg Stats / Ryan Hefner

smcloudstore-localstorage

v0.1.3

Published

LocalStorage provider for SMCloudStore

Readme

smcloudstore-localstorage

This package is a provider for SMCloudStore, for local storage hosting. SMCloudStore is a lightweight Node.js module that offers a simple API to interact with the object storage services of multiple cloud providers.

Please refer to the main package for the SMCloudStore documentation and instructions on how to use it.

Provider-specific considerations

There are a few provider-specific considerations for the LocalStorage provider.

Connection argument

When initializing the LocalStorage provider, the options argument is an object with:

  • options.signingFn: function(method, path, ttl) returning a String (which can be promised) which returns a publically accessible URL to download/upload from/to the specified path. It should also only last for ttl seconds. (generateRandUid() is exposed to help generate random URL IDs.)
  • options.basePath (optional): string representing the base path to store files in(default: ${__dirname}/storage)

Example:

// Require the package
const SMCloudStore = require('smcloudstore')

// Complete with the connection options for LocalStorage
const options = {
    signingFn: (method, path, ttl) => console.log("store the method/path/ttl combo in a DB for later use with a generic route"),
    basePath: __dirname + '/app/storage',
}

// Return an instance of the GenericS3Provider class
const storage = SMCloudStore.create('localstorage', options)

Using pre-signed URLs

In the storage.presignedPutUrl(container, path, [options], [ttl]) and equivalent get methods, the LocalStorage provider ignores the container and options argument, which have no effect.

What is returned, however, is a promise that is resolved using your signingFn function which should return a string (being the final URL). The design intent is to allow you to generate and store a link in your database with a reference to the file to get/put. This gives you full control over how you manage these links.

An example signingFn could be:

// Signing function
async function signingFn(method, path, ttl) {
    let token;
    let curUrl = await db.signedUrls.get(method, path);
    if(curUrl !== null) {
        token = curUrl.token;
        await db.signedUrls.update(method, path, token, Date.now() + (ttl * 1000));
    } else {
        token = storage.client.generateRandomUid();
        await db.signedUrls.put(method, path, token, Date.now() + (ttl * 1000));
    }
    return token;
}

// Usage in express
app.get('/download/:token', (req, res) => {
    let token = req.params.token;
    let url = await db.signedUrls.get(token);
    if(url !== null && url.expire > Date.now()) {
        if(url.method !== "get") return res.status(405).send("405 Method Not Allowed").end();
        return (await storage.getObject(null, url.path)).pipe(res);
    }
    else return res.status(404).send("404 Not Found").end();
});
// .. and do something similar for put

Accessing the LocalStorage library

The LocalStorage provider is built from the ground up and has a couple of additional helper functions, which are exposed by calling storage.client().

By accessing this object, you have access to:

  • generateRandomUid(),
  • sanitisePath(path)