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

serve-drive

v5.0.10

Published

HTTP drive server for entries delivery. Auto detects types like video, images, etc

Downloads

1,042

Readme

serve-drive

HTTP drive server for entries delivery. Auto detects types like video, images, etc

npm i serve-drive

Usage

Single drive:

const ServeDrive = require('serve-drive')
const Localdrive = require('localdrive')

const drive = new Localdrive('./my-folder')
await drive.put('/index.html', Buffer.from('hi'))

const serve = new ServeDrive({ get: ({ key, filename, version }) => drive })
await serve.ready()
console.log('Listening on http://localhost:' + serve.address().port)

// Try visiting http://localhost:49833/index.html

Multiple drives:

const Localdrive = require('localdrive')
const Hyperdrive = require('hyperdrive')
const Corestore = require('corestore')

const drive1 = new Localdrive('./my-folder-a')
const drive2 = new Hyperdrive(new Corestore('./store1'))

await drive1.put('/index.html', Buffer.from('a'))
await drive2.put('/index.html', Buffer.from('b'))

const serve = new ServeDrive({
  get ({ key, filename, version }) {
    if (key === null) return drive1 // Default
    if (key.equals(drive2.key)) return drive2
    return null
  }
})

await serve.ready()
console.log('Listening on http://localhost:' + serve.address().port)

// Try visiting http://localhost:49833/index.html?key=<id-or-key>

API

const serve = new ServeDrive([options])

Creates a HTTP server that serves entries from a Hyperdrive or Localdrive.

Available query params:

  • key to select which drive to use i.e. /filename?key=<id-or-key>.
  • version to checkout into a specific point i.e. /filename?version=<v>.

Available options:

{
  async get ({ key, filename, version }) {}, // Return the drive or null
  async release ({ key, drive }) {}, // Called after finishing a request to optionally release the drive
  port: 49833,
  host: '0.0.0.0',
  anyPort: true,
  server: null
}

serve.getLink(filename, [options])

Generates the full API link to a file.

options includes:

{
  https: false, // Set it to true to use https (default is false)
  host: '', // Custom host + port (default is localhost:server-port)
  key: '', // Drive id or key
  version: 0 // Checkout the drive into a previous point
}

await serve.suspend()

Let the instance know you wanna suspend so it can make relevant changes.

await serve.resume()

Let the instance know you wanna resume from suspension. Will rebind the server etc.

License

Apache-2.0