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

igloo-router

v1.0.1

Published

<img src="https://github.com/Dubsado/igloo-router/blob/main/docs/igloo-logo-day.png" height="100" />

Downloads

27

Readme

Disclaimer: This code is not "production-ready"... btw.

What is Igloo-Router?

Chill out, we've got you covered. Igloo-Router is a lightning-fast routing library for your server that's as cool as its name. With just 1.92KB of minified JavaScript code, it's so lightweight, you'd think it was made of snowflakes. 🌨️

Quick Start ❄️ 🚀

  1. Create Your Igloo (Project Folder):
mkdir myProject
cd myProject
  1. Initialize Bun:
bun init
  1. Install the Igloo-Router:
bun add igloo-router
  1. Copy one of the examples from below code into your project's index.ts then run it
bun run index.ts

Simple Routing Example

import { handler, router } from 'igloo-router'

//let's define some middleware
export const logRequest = (req: Request) => {
    console.log(req.method + ' - ' + req.url)
}

router.get('/health', logRequest, (req: Request) => {
    return new Response('hello')
})

router.get(
    '/random-json/:id',
    logRequest,
    (req: Request, params: { id: string }) => {
        return new Response(
            JSON.stringify({
                success: true,
                id: params.id,
            })
        )
    }
)

const server = Bun.serve({
    port: 3000,
    fetch: handler,
})

console.log(`
    d8b        888                 
    Y8P        888           http://localhost:${server.port}      
            888                 
    888 .d88b. 888 .d88b.  .d88b.  
    888d88P"88b888d88""88bd88""88b 
    888888  888888888  888888  888 
    888Y88b 888888Y88..88PY88..88P 
    888 "Y88888888 "Y88P"  "Y88P"  
            888                    
    Y8b d88P                    
        "Y88P"                     
`)

console.log('')
console.log('Logs: ', new Date().toLocaleString())

Example: List Routes

//additional dependency added here for print routes
import { handler, router, printRoutes, listRoutes, root } from 'igloo-router'

//let's define some middleware
export const logRequest = (req: Request) => {
    console.log(req.method + ' - ' + req.url)
}

// ...include your routes as we have defined them above

router.get('/', logRequest, () => {
    return new Response(
        `
    <html>
        <p>Hello, Bonjour, Hola, Привет, こんにちは, Olá</p>
        <p>This example will show you the power of being able to see what 
            dang routes you actually have on the server</p>
        ${Routes()}
    </html>
    `,
        {
            headers: {
                'Content-Type': 'text/html; charset=utf-8',
            },
        }
    )
})

//this is where we create the HTML for the landing '/' url
const routes = listRoutes(root)
const Routes = () => {
    const inner = routes
        .map((route) => {
            if (
                route.method === 'GET' &&
                !route.isDynamic &&
                route.path !== '/'
            ) {
                return `<li>${route.method} - <a href="${route.path}">${route.path}</a></li>`
            }
            return `<li>${route.method} - ${route.path}</li>`
        })
        .join('')
    return `
        <ul>
            ${inner}
        </ul>
    `
}

const server = Bun.serve({
    port: 3000,
    fetch: handler,
})

console.log(`
    d8b        888                 
    Y8P        888           http://localhost:${server.port}      
            888                 
    888 .d88b. 888 .d88b.  .d88b.  
    888d88P"88b888d88""88bd88""88b 
    888888  888888888  888888  888 
    888Y88b 888888Y88..88PY88..88P 
    888 "Y88888888 "Y88P"  "Y88P"  
            888                    
    Y8b d88P                    
        "Y88P"                     
`)

printRoutes()
console.log('')
console.log('Logs: ', new Date().toLocaleString())

Why Choose Igloo-Router?

  • Lean: Just 1.92KB of minified Javascript code.
  • Quick: Express functionality, without the performance hit.
  • Transparency: See your routes in action both on the console and the landing page. No more mysteries! 🕵️‍♀️

Conclusion

Still not convinced? Fine, go use one of those other "heated" routers. But when you're sick of them melting under pressure, you know where to find us.

❄️ Stay frosty, developers! ❄️

Feel free to share feedback or report issues. We're as obsessed with our users as a snowman is with winter. 🌨️💙

👉 Contribute on GitHub