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

micro-markdown

v0.9.0

Published

A markdown server.

Downloads

20

Readme

micro-markdown

A markdown server.

⚠️ Under active development; not stable! These docs are incomplete. ⚠️

micro-markdown is a markdown server. It serves both markdown files and markdown strings. It's built on top of Zeit's micro, and uses a redis cache by default. In the spirit of micro, micro-markdown tries to be as async as possible.

micro-markdown can be used as an API for rendering and serving markdown, or as a server for a markdown based website.

Markdown files

To serve a markdown file, add a file to the ./texts directory (this path is customizable).

<!-- ./texts/hello.md -->

# Hello, world.

I am some markdown.
// ./server.js
const server = require('micro-markdown')
/**
 * Start the server.
 * The rendered HTML will be available at `http://localhost:3000/mm/api/v1/html/hello`
 */
server().listen(3000)

Custom handlers

You can also pass a route handlers directly to micro-markdown:

// ./server.js
const server = require('micro-markdown')
/**
 * Start the server.
 * The rendered HTML will be available at `http://localhost:3000/mm/api/v1/html/example`
 */
server({
  routes: {
    example: {
      handler: () => ({ markdown: '# Hello, example.' })
    }
  }
}).listen(3000)

API

By default, micro-markdown renders three endpoints for each route:

  • /mm/api/v1/html/:endpoint: Returns the rendered HTML for :endpoint
  • /mm/api/v1/json/:endpoint: Returns a JSON object representing the provided markdown for :endpoint.
  • /mm/api/v1/raw/:endpoint: Returns the raw markdown string for :endpoint.

Route maps

You can pass route maps to micro-markdown to mirror existing endpoints. This is helpful if you want to use micro-markdown to serve a markdown-based website.

// ./server.js
const server = require('micro-markdown')
/**
 * Start the server.
 * The rendered HTML will be available at `http://localhost:3000/example`
 */
server({
  routes: {
    example: {
      handler: () => ({ markdown: '# Hello, example.' })
    }
  },
  routeMaps: {
    default: route => {
      // Resolve `/mm/api/v1/html/${foo}` to `/${foo}`
      return route.indexOf('/mm') === 0
        ? {}
        : { route: `${route}`, target: 'html' }
    }
  }
}).listen(3000)

Caching

Rendered markup is cached by default, using redis. To use the redis cache, provide the following environment variables:

REDIS_HOST="YOUR_REDIS_HOST" # Default `redis`
REDIS_PORT="YOUR_REDIS_PASSWORD" # Default `6379`
# Optional
REDIS_PASSWORD="YOUR_REDIS_PASSWORD"

By default, micro-markdown will flush the redis cache the first time it is called.

Why?

I wanted a simple server that would dynamically render and route markdown.

I tried other options:

  • Static site: Renders markdown, but requires a build.
  • SSR with React, Vue etc.: There are great tools for this. I couldn't find a good option that would let my dynamically render flat markdown files to custom routes, though.