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 🙏

© 2026 – Pkg Stats / Ryan Hefner

express-smart-router

v1.0.1

Published

Auto-load Express route files from folder structure with API versioning, extension filtering, and middleware support.

Readme

📦 express-smart-router

🔁 View this README in English

express-smart-router, Express.js projelerinizde route dosyalarını klasör yapısına göre otomatik olarak yükleyen, versiyonlama ve middleware gibi gelişmiş özellikleri destekleyen güçlü ve sade bir yönlendirme motorudur.


🚀 Öne Çıkan Özellikler

  • Otomatik route keşfiroutes/ klasörü ve alt klasörler recursive şekilde taranır
  • 📁 index.js & index.router.js → klasör köküne bağlanır (routes/admin/index.js/admin)
  • 📄 Uzantı desteği.js, .router.js, .route.js gibi uzantılar desteklenir
  • 🔍 match ile filtreleme – Regex ile sadece belirli uzantılardaki dosyalar yüklenebilir
  • baseRoute – Tüm route'lara ön ek ekleyebilirsiniz (örnek: /api)
  • 🔗 middleware – Tüm route'lara global middleware tanımlanabilir
  • 📣 verbose – Yüklenen route'lar terminalde listelenir
  • 💙 TypeScript desteği – Otomatik tanım dosyası (index.d.ts) ile uyumludur
  • Platform bağımsız – Windows, Linux, macOS desteği

📦 Kurulum

npm install express-smart-router

📁 Örnek Proje Yapısı

routes/
├── index.js                 → /
├── hello/
│   └── index.js             → /hello
├── auth/
│   └── login.route.js       → /auth/login
└── api/
    ├── v1/
    │   ├── index.router.js  → /api/v1
    │   └── user.router.js   → /api/v1/user
    └── v2/
        └── stats.js         → /api/v2/stats

🔧 Temel Kullanım

const express = require('express');
const path = require('path');
const smartRouter = require('express-smart-router');

const app = express();
app.use(express.json());

smartRouter(app, path.join(__dirname, 'routes'));

app.listen(3000, () => {
  console.log('🚀 Server running at http://localhost:3000');
});

⚙️ Tüm Seçenekler

🔁 baseRoute: Global ön ek tanımlama

smartRouter(app, path.join(__dirname, 'routes'), {
  baseRoute: '/api'
});
// routes/user.js → /api/user

🧠 match: Dosya uzantılarını filtreleme

Sadece .router.js ve .route.js uzantılı dosyaları yükle:

smartRouter(app, path.join(__dirname, 'routes'), {
  match: /\.(router|route)\.js$/
});

Varsayılan değer:

match: /\.js$/

Bu, .js, .router.js, .route.js dosyalarının tümünü içerir.


🔗 middleware: Tüm route'lara uygulanan global middleware'ler

const logger = (req, res, next) => {
  console.log(`[${req.method}] ${req.url}`);
  next();
};

smartRouter(app, path.join(__dirname, 'routes'), {
  middleware: [logger]
});

📣 verbose: Terminal loglarını kontrol et

smartRouter(app, path.join(__dirname, 'routes'), {
  verbose: false // hiçbir şey loglanmaz
});

✅ Route Eşleme Kuralları

| Dosya | Route | |------------------------------|-------------------| | routes/index.js | / | | routes/index.router.js | / | | routes/hello/index.js | /hello | | routes/api/v1/index.router.js | /api/v1 | | routes/api/v1/user.route.js | /api/v1/user | | routes/api/v2/stats.js | /api/v2/stats |

📌 Sadece index.js ve index.router.js özel dosyalardır, diğer dosyalar adlarına göre route'lanır.


🟦 TypeScript Desteği

import express from "express";
import smartRouter from "express-smart-router";
import path from "path";

const app = express();

smartRouter(app, path.join(__dirname, "routes"), {
  baseRoute: "/api",
  match: /\.(router|route)\.js$/,
  verbose: true,
});

🧪 Test Ortamı

  • ✅ Node.js 14+
  • ✅ Express 4.x ve üzeri
  • ✅ TypeScript 4.x ve üzeri

📝 Lisans

MIT Lisansı


👨‍💻 Geliştirici

Eren Seyfi
GitHub