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

mode-server

v1.0.1

Published

A configurable lightweight Node server that supports middleware, static resources, request brokers, and route management capabilities.

Downloads

16

Readme

mode-server

一个简易配置的轻量级node服务器

A configurable lightweight Node server that supports middleware, static resources, request brokers, and route management capabilities.

  • 一个轻量级node服务器,支持中间件
  • 多个配置项包括静态资源、请求代理、路由管理
  • 可同时开启htpp和https监听

Install

npm i mode-server

基础配置项

const server = require('mode-server')
const path = require('path')
app = server({
  quick: {
    open: true,
    staticSwitch: true,
    proxySwitch: true,
    routerSwitch: true
  },
  isQuick: false, //快速模式 false需要自己手动use中间件
  http: {
    open: true,
    port: 3000,
    option: {}
  },
  https: {
    open: true,
    port: 3443,
    key: './key.pem', //https证书私钥
    cert: './cert.pem', //https证书
    option: {}
  },
  staticPath: __dirname, //静态资源目录,快速模式需要配置
  proxyConfig: { //需要代理的目标对象,快速模式需要配置
    '/api': {
      target: 'https://proxyhost.com/target/url', //代理的目标地址
      referer: true, //是否代理修改请求的来源为代理地址,会修改请求头的referer,Host为本地服务器地址
      pathRewrite: { //重写
        '^/api': ''
      }
    }
  },
  router: [ //路由,快速模式需要配置,下一版本的工作

  ]
})

快速启动模式quick:{open: true}:

app.router.use('/test', (request, response) => {
  response.body = "The request name is '/api/test'"
})
app.router.use('/getList', (request, response) => {
  response.status(200)
  response.json({
    list: [1, null, true, 'abc', '文字']
  })
})

app.router.use('/error', (request, response) => {
  response.status(500)
  response.body = 'server error...'
})

app.start()

手动use中间件,quick: false的情况,可以引入其它自由中间件

中间件

  1. 代理中间件
  const ProxyServer = require('mode-server/src/middleware/proxy')
  const proxy = new ProxyServer({
    '/api': {
      target: '/proxyurl', 
      referer: true,
      pathRewrite: {
        '^/api': ''
      }
    }
  })
  app.use(async (ctx, next) => {
    return await proxy.match(ctx, next)
  })
  1. 静态资源中间件
  const StaticServer = require('mode-server/src/middleware/static')
  const static = new StaticServer({
    dirname: __dirname
  })
  app.use(async (ctx, next) => {
    return await static.match(ctx, next)
  })
  1. 路由中间件
  const router = new Router()
  const Router = require('mode-server/src/middleware/router')
  app.use(async (ctx, next) => {
    return await router.match(ctx, next)
  })
const server = require('mode-server')
const path = require('path')
app.start()

request

属性

  • url url
  • hostname 域名
  • port 端口
  • path 请求路径
  • query url上的参数
  • params body上的参数

response

response.status() 设置返回的状态码 response.json() 设置返回的json字符串