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

min-route

v1.0.4

Published

A simple and lightweight library to manage server side routes.

Downloads

22

Readme

min-route

npm npm bundle size install size

Description

A simple and lightweight library to manage server side routes. It uses only 4 routes for whole project. It is based on Rest API and it is not a replacement of GraphQL but similar to it

Install

$ npm i min-route

Basic Usage

Server index file

const express = require('express');
const minRoute = require('min-route')

const app = express();

minRoute.api(app, [<path of controller file 1>, <path of controller file 2>, ...... <path of controller file n>])

app.listen(<port-number>, () => {});

Controller file

Add the name of the controller in all your controller file's first line.

Syntax - /** @controller = <name> **/

Example-

/** @controller = controller001 **/

//require all the libraries below @controller line
const someLibrary = require('some-library');


const getUser = async (req, res) => {
  //your logic here
    return res.status(200).send({message: "Message"});
}

const postUser = async (req, res) => {
  //your logic here
    return res.status(200).send({message: "Message"});

}

module.exports = {
    getUser,
    postUser
}

Function call from client side

Here-
3000 is the server's port number
controller001 is name of controller file which we defined in server's controller file
getUser is the function defined in the controller file
{"param1":"value1", "param2": "value2"} is the object of paramters

Note -

  1. seperate controller name and function name with a dot (.)
  2. parameters should be in an object
let baseUrl = "http://localhost:3000/";
let config = {
	serverFunction:"controller001.getUser/",
  //seperate the controller name and the function name with a dot
	params: {"param1":"value1", "param2": "value2"},
  //parameters should be in an object
	method: "GET"
  }
let reqOptions = {
  url: config.baseUrl + config.serverFunction + config.params,
  method: config.method
  headers: headersList,
  data: bodyContent,
}

axios.request(reqOptions).then(function (response) {
  console.log(response.data);
})

Shorthand

axios.request(url: "http://localhost:3000/controller001.getUser/{"param1":"value1", "param2": "value2"}",
  method: "GET"
  headers: headersList,
  data: bodyContent,).then(function (response) {
  console.log(response.data);
})

Advanced Usage

Custom Middleware

From Client side send middleware array in the parameter object like this-

Note -

  1. Parameter name should be middleware
  2. seperate controller name and function name with a dot (.)
let baseUrl = "http://localhost:3000/";
let config = {
	serverFunction:"controller001.postUser/",
  //seperate the controller name and the function name with a dot
	params: {"param1":"value1", "param2": "value2", "middleware": ["controller002.multerFunction", "controller003.authenticateFunction"]},
  //add a middleware key and pass the middleware functions in an array.
  //seperate the controller name and function name with a dot.
	method: "POST"
  }
let reqOptions = {
  url: config.baseUrl + config.serverFunction + config.params,
  method: config.method
  headers: headersList,
  data: bodyContent,
}

axios.request(reqOptions).then(function (response) {
  console.log(response.data);
})

Shorthand

axios.request(url: "http://localhost:3000/controller001.postUser/{"param1":"value1", "param2": "value2", "middleware": ["controller002.multerFunction", "controller003.authenticateFunction"]}",
  method: "POST", // or GET/PUT/DELETE
  headers: headersList,
  data: bodyContent,).then(function (response) {
  console.log(response.data);
})

License

MIT