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

route-scanner

v0.2.2

Published

just easy to use, aimed to load route fastly and conveniently.

Downloads

4

Readme

route-scanner

npm package 

English | 中文

Recent version: v0.2.2

Release History

See the Change Log

Introduction

This module is a tiny tool just for scan some route file in a directory, you can use it to load masses of route files fastly and conveniently.

Quick Start

First of all, you need install route-scanner to your project:

npm i route-scanner --save

then, import the module and initialize it in your app.js just like below:

const routeScanner = require('route-scanner');
......

routeScanner(app,{
    debug:false,
    framework:'express',    // express or koa2
    routerPath: path.join(__dirname, 'routes'),
    prefix:'std',   //  modifier
    replacePaths:[{
        from:'/index',
        to:'/'
    }],
    extraMaps:[{
        rootPath:path.join(__dirname, '/core/base-routes'),
        fileMaps:[{
            url:'/admin',
            file:'admin.js'
        }]
    }]
});
......
// other express codes to use middleware
module.exports=app;

after that, you can create any router file in directory /routes/, and don't write use sentence in app.js.

Configuration

debug

You can set debug:true to open scan logs print.

{
    debug:true
}

framework

You can set express or koa2 to specify the framework, if empty , express is default.

{
    framework:'express'
}

routerPath

Specify the root for those route files. It's an absolutly path, so you can input like this:

{
    routerPath: path.join(__dirname, 'routes'),
}

prefix

Specify the prefix of the url, if you fill a string, then your root url turned to http://localhost:3000/string, and also, the empty value is possible.

{
    prefix:'yourProjectName'  // url is http://localhost:3000/yourProjectName
}
// or 
{
    prefix:''     // url is http://localhost:3000
}

replacePaths

If you want to change a file name to an other url, you can use this option:

{
    replacePaths:[{
        from:'/index',
        to:'/mgr/index'
    }],
    // enter http://localhost:3000/mgr/index will directed to index.js
}

then, the route file /routes/index.js will be mapped to /mgr/index, so the full url is http://localhost:3000/mgr/index, when you enter this url , it will be directed to index.js

extraMaps

Specify another path to load other route files, you can use it like below:

{
    extraMaps:[{
        rootPath:path.join(__dirname, '/another-routes-path'),
        fileMaps:[{
            url:'/admin',
            file:'admin.js'
        },{
            url:'/service',
            file:'/subdir/service.js'
        }]
    }]
}

Just support a way to mapping file and url, you can use it easily

License

Copyright (c) 2020 George under the MIT License