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

node-server-router

v1.0.2

Published

Simple way to create routes on Node.js server w/ added complex options.

Downloads

97

Readme

node-server-router

This packages provides and easy way to create dynamic routing on your NodeJS & ExpressJS server. It allows you to add API route files to any directory and bind them all to the ExpressJS Application instance.

NPM version js-standard-style Maintenance Documentation LICENSE

Prerequisites

As most NodeJS projects require, please ensure you have NodeJS installed; install here

Install

Using npm:

npm install node-server-router --save

Using yarn

yarn add node-server-router

Usage

ECMAScript Modules

Basic usage:

import express from "express";
import * as nsr from "node-server-router";

const app = express();
nsr.RouteFactory.applyRoutesTo(app);

app.listen(6969);

CommonJS

Basic usage:

const nsr = require("node-server-router");
const app = require("express")();

nsr.RouteFactory.applyRoutesTo(app);

app.listen(6969);

Using options config settings:

const nsr = require("node-server-router");
const app = require("express")();

nsr.RouteFactory.applyRoutesTo(app, {
  api_version: "/v1",
  log_configured: true,
  route_dir: "routes",
});

app.listen(6969);

Route Structure

All route files need to follow the following structure:

import { HTTPAction } from "node-server-router";

// @type {Array<Route>}
export default [
    {
        url: "/dog:id",
        action: HTTPAction.GET,
        handlers: [...]
    }
];

Documentation

Config

Configuration will allow you to specify unique items to your server. All config properties are optional.

Example config structure:

const config = {
    route_dir: "routes",
    api_version: "/v1",
    log_configured: false
}

Options

| Prop name | Optional | type | Default | Description | | --------- | -------- | ---- |------- |----------- | | route_dir | yes | string | routes | The folder were your routes reside. e.g if the passed values is routes it will be interpreted as ./routes; /folder1/folder2 is ./folder1/folder2. | | api_version | yes | string | / | API verison identifier. e.g '/v1' resulting in http://localhost:6969/v1/... | | log_configured | yes | boolean | false | Logs to the console when routes are successfully configured. |

Example usage of any or all combinations of config props:

// ...
nsr.RouteFactory.applyRoutesTo(app, { route_dir: "/services/main/routes" });
// ...

Examples

You can find simple examples for the 4 supported types of Node.js Servers:

License

MIT