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

hyper-routing

v0.0.1

Published

An amazing and simple route manager

Downloads

2

Readme

Hyper-Routing

version license downloads

An amazing and simple route manager

Instalation

npm i hyper-routing

Table of contents

Usage

// Using Node.js `require()`
const hyperRouting = require('hyper-routing');

// Using ES6 imports
import hyperRouting from 'hyper-routing';

const app = new hyperRouting()

Application instance

<method>(path, ...callbacks)

app.get('/', (req, res, next) => {
    // Do something
});

app.post('/', (req, res, next) => {
    // Do something
});

use(middleware)

Uses a middleware function in all routes.

/* Creating own middleware */
const myOwnMiddleware = (req, res, next) => {
    console.log("Hello world!") 
    console.log(`I was called on ${req.url}`)
    next(); // Important to pass control to next middleware function
}

app.use(myOwnMiddleware)

listen(port, callback)

Starts the server in the desired port.

app.listen(3000, () => {
    // Do something
});

Middlewares

bodyparser({...parser})

Parses the req data into object readable data.

app.use(app.bodyparser()) // Will parse both application/json and www-x-form-urlencoded data
app.use(app.bodyparser({ json: true })) // Will only parse application-json data
app.use(app.bodyparser({ urlencoded: true })) // Will only parse www-x-form-urlencoded data

Request

body

Attribute of the Request class containing the <input/> values of the <form/> with key based in their names attribute.

<form action="/login">
    <input type="text" name="username">
    <input type="password" name="password">
    <button type="submit">Login</button>
</form>
{
    username: "someusername",
    password: "somepassword"
}
app.post('/login', (req, res) => {
    const { username, password } = req.body;
});

params

Attribute of the Request class with the specified parameters in the path.

// http://localhost:3000/users/12345
{
    id: "123458"
}
// http://localhost:3000/users/12345
app.get('/users/:id', (req, res) => {
    const { id } = req.params;
    console.log(id); // Logs 123458
});

query

Attribute of the Request class with the query parameters in the url.

// http://localhost:3000/products?category=clothes&design=fancy&sort=recent
{
    category: "clothes",
    design: "fancy",
    sort: "recent"
}
// http://localhost:3000/products?category=clothes&design=fancy&sort=recent
app.get('/products', (req, res) => {
    const { category, design, sort } = req.query;
    console.log(category); // Logs clothes
    console.log(design); // Logs fancy
    console.log(sort); // Logs recent
});

Response

status(code)

Sets the response status code.

app.get('/', (req, res) => {
    res.status(404) // Status Code: 404
    res.status("Not Found") // Status Code: 404
});

json(data)

Sends an application/json content-type response.

app.get('/', (req, res) => {
    res.json({
        username: "Álvaro",
        age: "16"
    }) // Will display a JSON object
});

send(data)

Sends a text/plain content-type response.

app.get('/', (req, res) => {
    res.send("An amazing webpage :)")
});

app.get('/', (req, res) => {
    res.send({ // As this is an object it will trigger res.json()
        data: "An amazing webpage :)" 
    })
});

sendFile(path)

Sends a text/html content-type response.

app.get('/', (req, res) => {
    res.sendFile("index.html")
});

redirect(url)

Redirects to the specified url.

app.get('/profile', (req, res) => {
    if(!req.user) { // Using some type of auth
        res.redirect('/login'); // Redirects the user to http://localhost:3000/login
    };
});

Examples

Check out the examples to see how you can use hyper-routing in a project.

Help

Have any doubts or suggestions? Send me a private message on Discord: @newalvaro9

License

MIT

Copyright 2023, Álvaro Poblador. Inspired in express.js