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

stancy

v1.0.0-alpha.28

Published

A simple API for delivering content from static files and folders.

Readme

Stancy

npm

Stancy uses static files and folders to generate a database of collections and items. The database can be queried as a plain object, outputted as a json file, or served using an express server for a RESTlike API. This is useful for building static sites which use frameworks like React, Vue, Svelte or Marko. Stancy is unbiased about how you use it and can be customised to suit different use-cases.

Example

In this example, we'll look at how we can create a database from static files and folders which can be accessed using an API for a website.

Start by creating a folder with some content, below is an example. Each top level file or folder creates a root endpoint.

content/
  site.json
  pages/
    home.md
    about.md
    services.md
    blog/
        index.md
        my-first-post.md
        another-post.md

Here we've created a file site.json which stores key information about our site, some pages, and a blog.

Now start the server.

stancy('content/').serve(3000, '/api/')

We can access the content using the following requests:

Items in collections can be filtered by querying their fields. For example the query ?status=draft will list all draft pages.

Check out the examples.

Installation

Add the npm package to your project.

npm install stancy --save-dev

Import stancy in your application.

import stancy from 'stancy'

Features

  • Server and client

    Easily serve content from static folders and files, and fetch content.


  • Collections and Items

    Collections are created by plural sounding folders. Items are created using folders.


  • Preprocess data

    Easily sort collections, format dates, and parse content on the client.


  • Index File

    This is useful if you prefer to organise using folders or if you want to create an index page for a group of related content.

    # Creates a collection of items
    posts/
      item-one.md
      item-two.md
      item-three.md
    
    # Creates an item
    item/
      index.md

  • Hidden

    Prepend an underscore to hide a file or folder. In the case of hiding a folder, this will also hide all it's contents.

    _file-is-hidden.md
    _folder-is-hidden/

  • File Types (Planned)

    The following file types are supported.

    • Archives
    • Audio
    • Code
    • Documents
    • Images
    • Videos

  • Meta Data (Planned)

    You can add meta data to images by creating a data file with a matching name.

    my-first-post/
      playing-frisbee.jpg
      playing-frisbee.yml

    This will create the following image meta data

    {
      // ...
      "images": [
        {
          "src": "/static/playing-frisbee.jpg",
          "alt": "Me playing frisbee"
        }
      ]
    }

  • Built in Fields

    If you create a database you can filter and show data using a query language of your choice using the following field names.

    Private

    • _name Name of the resource
    • _collection Collection the resource belongs to
    • _index The index of the resource in the collection or dataset
    • _type The type of resource. Named after the folder or file.
    • _source The path to the folder containing the file.

    Public

    • url The url to the resource.

Docs

  • Starting a server

    stancy(source).server([port, path])

    Arguments

    • source { String } source of the content directory to be servered
    • port { Number }
    • path { String } subpath where API will be accessible from

    Example

    stancy('content/').server(3000, '/api/')

  • Starting a client

    stancy([source]).client(url)

    Arguments

    • url { String } url of the production server

    Example

    stancy('content/').client('http://domain.com/api/')

  • Preprocessing data

    client.preprocess([type,] callback)

    Useful for sorting collections, formatting dates, or parsing markdown.

    Arguments

    • type { String } can be one of the following:
      • collection returns every collection as an array of objects.
      • item returns every item as an object with key value pairs.
      • content returns value of every item with a property of content.
    • callback { function } gives access to one of the types of data above.

    Examples

    An example of sorting collections by date

    client.preprocess('collection', (data) => {
        return data.sort((a, b) => {
            if (a.date > b.date) {
                return 1;
            } else if (a.date < b.date) {
                return -1
            } else {
                return 0
            }
        })
    })

    An example of formatting machine readable dates

    client.preprocess('item', (data) => {
        return data.date = new Date(data.date)
    })

    An example of parsing markdown

    client.preprocess('content', (data) => {
        return marked(data)
    })

  • Getting data

    client.get('users/jerry').then(res => {
        console.log(res)
    }).catch(err => { 
        console.log(err)
    })

    Example response

    {
        "url": "users/jerry",
        "name": "Jerry",
        "age": "24",
        "role": "admin",
        "content": "<h1>Jerry</h1>"
    }

  • Creating a database

    stancy(source).database()

    Example

    var database = stancy('content/').database()

  • Configure using config file (Planned)

    stancy.config.js

    {
        source: 'content/',
        client: {
            production: 'https://stancy.now.sh/api/',
            token: 'T89ALS90',
            preprocess: ({content}) => {
                content = marked(content)
            }
        }
    }

    Specify custom config file

    stancy().config('src/stancy.config.js')

Development

To install the dependencies

npm install

To run the demo server

npm run demo

To run tests

npm run test