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

zowwu

v0.1.5

Published

The easiest way to create a RESTful endpoints.

Downloads

6

Readme

Node.js CI LICENCE

About The Project

Just don't waste any time. If you're building a project, you probably have a clean folder structure anyway. Zowwu uses the folder structure and automatically creates your API endpoints based on polka from it.

The project is still in progress. Support is greatly appreciated.

Installation

  1. Install Package
    npm install zowwu
    or
    yarn add zowwu

Usage

Server

   ./index.js
const loader = require("zowwu");

loader().then((app) => {
  app.listen(3000, (err) => {
    if (err) throw err;
    console.log(`> Running on localhost:3000`);
  });
});

Create your folders or files

   ./api/comments/index.js  -> http://localhost:3000/comments
   ./api/comments/deeper/index.js  -> http://localhost:3000/comments/deeper
   ./api/articles/index.js  -> http://localhost:3000/comments
   ./api/...

or

   ./api/comments.js  -> http://localhost:3000/comments
   ./api/articles.js  -> http://localhost:3000/articles
   ./api/...
module.exports = {
  routes: [
    {
      action: async (req, res, next) => {
        res.json({ status: "Hello world" });
      },
    },
  ],
};

🪄 Now your routes are automatically created based on the file names and/or folder structure

Route Options

module.exports = {
  routes: [
    {
      // path: path of the route
      // - type: String
      // - default: '/'
      path: '/',
      // method: method
      // - type: String
      // - default: 'GET'
      // - available: 'GET', 'HEAD', 'PATCH', 'OPTIONS', 'CONNECT', 'DELETE', 'TRACE', 'POST', 'PUT'
      method: 'GET',
      // Before Handler
      // - type: Function | Array
      before: async (req, res, next) => ...,
      // Main Handler
      // - type: String
      action: async (req, res, next) => ...
    },
  ],
};

The supported route pattern types are:

  • static (/messages)
  • named parameters (/messages/:id)
  • optional parameters (/messages/:id?)
  • suffixed parameters (/movies/:title.mp4, movies/:title.(mp4|mov))
  • any match / wildcards (/messages/*)

Not supported pattern types are (if folder-specific is to be created):

  • deep nested parameters (/messages/:id/books/:title)
  • deep optional parameters (/messages/:id?/books/:title?)

However, within the route option (module.exports.routes) these route methods are possible. 📄 For more information - polka based on trouter.

Now you can query

 curl http://localhost:3000/articles
 curl http://localhost:3000/comments
 ...

👩‍🔧 Available options:

const loader = require("zowwu");

loader({
  // entry: the folder where routes are scanned for
  // - type: String
  // - default: 'api'
  entry: 'api',
   // debug: it shows you the generated routes on load
  // - type: Boolean
   // - default: false
  debug: true,
  // pluginPath: the folder where plugins are scanned for
  // - type: String
  // - default 'plugins'
  pluginPath: 'plugins',
  // register: Initialize external modules. Similar to app.use(module)
  // - type: Array
  // - default: []
  register: []
}).then(app => // return the polkajs instance

Middlewares (Endpoint specific)

function one(req, res, next) {
  console.log("world...");
  next();
}

function two(req, res, next) {
  console.log("...needs better demo 😔");
  next();
}

module.exports = {
  before: [one, two],
  routes: [
    {
      action: async (req, res, next) => {
        // Get Posts
        res.json([{ title: "Post..." }]);
      },
    },
    {
      path: "/:id",
      action: async (req, res, next) => {
        // Get Posts
        res.json([{ title: `Hello ${req.params}` }]);
      },
    },
    {
      method: "POST",
      path: "/",
      action: async (req, res, next) => {
        // Create Post
        res.end("Create Post...");
      },
    },
  ],
};

Middlewares (Route specific)

function one(req, res, next) {
  console.log("world...");
  next();
}

function two(req, res, next) {
  console.log("...needs better demo 😔");
  next();
}

module.exports = {
  routes: [
    {
      before: [one, two],
      action: async (req, res, next) => {
        // Get Posts
        res.json([{ title: "Post..." }]);
      },
    },
    {
      method: "POST",
      path: "/",
      before: two,
      action: async (req, res, next) => {
        // Create Post
        res.end("Create Post...");
      },
    },
  ],
};

Plugins

Plugins work like normal routes. For example, you can provide the authentication function as a plugin or other functions.

Create your folders or files

   ./plugins/myplugin.js
   or
   ./plugins/myplugin/index.js
   ./plugins/...

Note: With the plug-ins, you cannot go deeper into the folder structure.

// ./plugins/myplugin.js  or  ./plugins/myplugin/index.js
module.exports = {
  routes: [
    {
      action: async (req, res, next) => {
        res.json({ status: "Hello plugin" });
      },
    },
  ],
};
// ./api/myroute.js
module.exports = {
  routes: [
    {
      plugin: "myplugin",
    },
    {
      path: "/:id",
      action: async (req, res, next) => {
        res.json({ status: req.params.id });
      },
    },
  ],
};

🤟 You can still add your middlewares here or overwrite the plugins:

// ./api/myroute.js
module.exports = {
  routes: [
    {
      plugin: "myplugin",
      before: async (req, res, next) => {
        console.log("before.. but after plugin function");
        next();
      },
      action: async (req, res, next) => {
        res.json({ status: "overwrite plugin" });
      },
    },
    {
      path: "/:id",
      action: async (req, res, next) => {
        res.json({ status: req.params.id });
      },
    },
  ],
};

Modules

Modules can be initialized using the register array.

const loader = require("zowwu");
const { json } = require("body-parser");

loader({ register: [json()] }).then((app) => {
  app.listen(3000, (err) => {
    if (err) throw err;
    console.log(`> Running on localhost:3000`);
  });
});

Roadmap

See the open issues for a list of proposed features (and known issues).

Contributing

Contributions are what make the open source community such an amazing place to be learn, inspire, and create. Any contributions you make are greatly appreciated.

  1. Fork the Project
  2. Create your Feature Branch (git checkout -b feature/AmazingFeature)
  3. Commit your Changes (git commit -m 'Add some AmazingFeature')
  4. Push to the Branch (git push origin feature/AmazingFeature)
  5. Open a Pull Request

License

Distributed under the MIT License. See LICENSE for more information.

Contact

Tayfun Gülcan - Twitter LinkedIn

Acknowledgements