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

@djoerkie/routify

v1.0.6

Published

Api router based on folders and file names.

Downloads

16

Readme

Features 🚀

  • Routes are file and folder based
  • Params are supported
  • Routes can be nested

Installation 📦

The project requires a working node.js installation, if you do not have it installed please do this first.

npm install djoerkie@routify

Usage 📚

import { routify } from "@djoerkie/routify";
const routify_instance = new routify(3000); // 3000 is the port
routify_instance.init('./routes'); // './routes' is the folder where the routes are located

You can now make a folder called 'routes' and put files/folders inside it. The file/folder names will be used as the route.

export default function get(res: any, req: any) {
    res.json({ message: "Hello World!" });
}

You can rename the function 'get' to one of the following names:

  • get
  • post
  • put
  • delete
  • patch
  • options
  • head

This example will make the route postable.

export default function post(res: any, req: any) {
    res.json({ message: "Hello World!" });
}

You can make a new folder and put routes inside it. The folder name will be used as the route prefix and the routes inside the folder will be accessible. For example:

  • /api/hello will need a folder called api and a file called hello.ts/js

You can also use a '.' in the file name to make a subroute. For example:

  • /api/hello/world will need a folder called api and a file called hello.world.ts/js

Parameters

You can add params to the route by surrounding the file name with '[param]', for example [userid] will be hosted at localhost:port/userid and the param will be available in the request object.

export default function get(res: any, req: any) {
    res.json({ message: req.params.userid });
}

Adding modules

You can add middleware to the app by adding it in the options object while initializing the app.

import { routify } from "@djoerkie/routify";
const routify_instance = new routify(3000);
routify_instance.init('./routes', {
    middleware: [
        (req: any, res: any, next: any) => {
            console.log("Middleware 1");
            next();
        }
    ]
});

Or pass body-parser for example:

import { routify } from "@djoerkie/routify";
const routify_instance = new routify(3000);
routify_instance.init('./routes', {
    middleware: [
        bodyParser.json(),
        bodyParser.urlencoded({ extended: true }),
    ]
});

Getting info

You can get the express app object by calling the getApp method.

import { routify } from "@djoerkie/routify";
const routify_instance = new routify(3000);
routify_instance.init('./routes');
const app = routify_instance.getApp();

You can get the routes object by calling the getRoutes method.

import { routify } from "@djoerkie/routify";
const routify_instance = new routify(3000);
routify_instance.init('./routes');
const routes = routify_instance.getRoutes();

You can get the port by calling the getPort method.

import { routify } from "@djoerkie/routify";
const routify_instance = new routify(3000);
routify_instance.init('./routes');
const port = routify_instance.getPort();

License 📝

MIT © djoerkie