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

fdy

v2.0.1

Published

a simple file server with some features

Downloads

21

Readme

fdy is a simple, effortless file server with nifty features such as URL rewriting (see fdy.replace), file directory listing, and file manipulation (see fdy.handle)

##do it

var fdy=require("fdy");
fdy.listen(80);

##Settings

Settings including cache, index, and directory were removed as of 2.0.0. Directory now defaults to ./public

####fdy.on(event, callback)

Handle events. Currently the only event is "request".

  • event String
  • callback Function(request, response)

####fdy.header(type, header)

Set headers for specific file mimetypes (ex. text/plain) or general types (ex. text/*).

  • type String
  • header Object
fdy.header("image/*", {
    "Cache-Control": "max-age=3600"
    });

####fdy.hide(path)

As of 0.0.1, only allows a single RegExp As of 1.0.5, functions similarly to replace As of 2.0.0 (current), only accepts specific path or file names

  • path String

####fdy.replace(regex, string)

Make changes to path before handling (i.e. /js//files/js/).

  • regex RegExp | String
  • string String (Function would also work, as it is a regular replace)

####fdy.redirect(regex, string)

Serve 302 to specified path (i.e. /blog/http://external.blog/).

  • regex RegExp | String
  • string String

####fdy.forbidden(regex, files)

Serve 403 from specified path (if directory, also excludes files by default).

  • regex RegExp | String
  • files Boolean (true to allow direct file requests such as images)

####fdy.handle(path, callback[, exists])

Manipulate select data before sending it. The first argument determines what requests a handle applies to based on url.

exists (default false) determines whether a file is expected to already exist (enabling the data field in the callback). If false or undefined, the handle is called without loading the file.

  • path String
  • callback Function(request, response[, data], query)

##Pages

Currently supports 403, 404 and DIR -- point to files to serve for respective pages. Grabs from ./public since any external files (such as stylesheets) would have to be public as well.

app.js

fdy.hide("pages");
fdy.page("403", "pages/forbidden.html");
fdy.page("404", "pages/not-found.html");
fdy.page("DIR", "pages/directory.html");

directory.html The directory page uses a special jht format since its content is dynamic.

<title>index of {path}</title>
<table width="100%">
    <thead>
        <tr>
            <th>File</th>
            <th>Size</th>
            <th>Modified</th>
        </tr>
    </thead>
    <tbody>
        {each files}
            <tr>
                <td><a href="{path}">{name}</a></td>
                <td>{size}</td>
                <td>{date}</td>
            </tr>
        {/each}
    </tbody>
</table>

##Help, stuff broke!

There have been significant changes with each update and for the sake of moving forward backwards compatibility has not been a huge concern. You can use a previous version or just rename a few functions in your code (i.e. fdy.set became fdy.page). Your biggest burden is probably going to be updating your custom DIR template if you have one, and for that I apologize.