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

dhost

v0.3.5

Published

Never-caching development Node webserver

Downloads

1,508

Readme

The never-caching development Node webserver for static files and ESM dev work. This instructs browsers never to cache any requested resources. If you've ever had to mash Ctrl/Cmd-R to ensure your browser is seeing the latest version of a static site, you'll know this feeling.

Install globally via npm -g install dhost or yarn global add dhost, then run dhost.

⚠️ This is just for development. Don't use it in any sort of production. It reqiures Node 14+.

Running

Run dhost -h to list all flags flags. By default, this hosts only on localhost, on the first available port 9000 or above, and copies the serving URL to your clipboard (works on macOS, or if the optional clipboardy is found).

If you need to serve CORS requests, run with -c; if you need to rewrite ESM imports in JS files, run with -m.

Magic

The goal of this server is not to surprise you, and to avoid magic where possible. Its behavior will never intentionally match any particular hosting platform's semantics.

Here are the exceptions:

  • We serve index.html if found, or generate a simple directory listing otherwise
  • Symlinks generate a 302 to their target file if it's within the root (serve contents instead via -l)
  • No data is served for other status codes (i.e., your browser will render its own 404 page)

Modules

✨ New! ✨ Specify -m to rewrite your JS to include static ESM imports (e.g., "viz-observer" => "/node_modules/viz-observer/index.js").

This only works on static imports (e.g., import 'foobar';'), not dynamic ones (e.g., import('foobar')), as these can be any string (including ones generated at runtime). If you need to dynamically import from node_modules, add an extra helper file which doesn't need to be rewritten:

// your code
const foobarModule = await import('./foobar-wrapper.js');

// foobar-wrapper.js
export * from 'foobar';

Your build tools will compile this out, so the extra step won't effect a production build.

Note that this doesn't rewrite the modules themselves; you'll need to depend on packages that support ESM. (But you should be doing that anyway, it's 2021.)

Middleware

This can be used as middleware. To serve the current directory—without caching—using Polka:

const polka = require('polka');
const dhost = require('dhost');  // or: import dhost from 'dhost';

polka()
  .use(dhost({ /* optional options */}))
  .listen(3000, (err) => {
    // ...
  });

Dependencies

This package has a handful of dependencies, none of which have further dependencies.

Needed for the middleware only:

  • he escapes names in generated directory listing
  • mime guesses mime-types for the Content-Type header

Included for module rewriting support:

  • gumnut for ESM rewriting support
  • esm-resolve for resolving imports
  • async-transforms for running rewriting in parallel on multiple threads

Included for the CLI:

  • bytes displays nicely-formatted file sizes
  • colorette for color output
  • mri parses command-line arguments