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

ngate

v0.1.0-alpha.1

Published

一个静态文件服务器

Readme

ngate

npm version License: MIT Node.js Version

一个轻量级的静态文件服务器,可以运行静态网站,或者直接将文件夹作为服务提供访问。

功能特点

  • 🚀 快速启动静态文件服务
  • 📁 支持文件夹目录浏览
  • 🔄 支持API代理转发
  • 🗜️ 支持Gzip压缩
  • 🌐 支持CORS跨域访问
  • 💾 支持自定义缓存控制
  • 🖥️ 支持自动打开浏览器
  • ⚙️ 支持配置文件

安装

全局安装

npm install -g ngate

本地安装

npm install ngate

使用方法

命令行参数

用法: ngt [选项]

选项:
  -V, --version              输出版本号
  -p, --port <port>          服务器端口号 (默认: "8080")
  -d, --directory <path>     要服务的目录路径 (默认: 当前工作目录)
  -c, --compress             启用gzip压缩
  --cors                     启用CORS支持
  --cache <seconds>          设置缓存过期时间(秒)(默认: "3600")
  --proxy <urls>             设置代理转发规则,格式如 "/api:http://localhost:3000"
  --open                     启动服务器后自动打开浏览器
  -q, --quiet                静默模式,减少日志输出
  --config <path>            指定配置文件路径
  --no-config                忽略配置文件,仅使用命令行参数
  -h, --help                 显示帮助信息

基本用法

启动当前目录的文件服务

ngt

指定端口和目录

ngt -p 3000 -d ./dist

启用压缩和CORS

ngt -c --cors

配置代理

ngt --proxy "/api:http://localhost:8000"

多个代理规则

ngt --proxy "/api:http://localhost:8000,/auth:http://localhost:9000"

使用指定的配置文件

ngt --config ./ngate.config.js

忽略配置文件,仅使用命令行参数

ngt --no-config -p 3000

配置文件

ngate支持使用配置文件来设置服务器选项。配置文件优先级:

  1. 命令行参数(最高优先级)
  2. 通过--config选项指定的配置文件
  3. 当前目录中自动发现的配置文件
  4. 默认配置

支持的配置文件名(自动发现):

  • ngate.config.js
  • ngate.config.json
  • .ngaterc
  • .ngaterc.json
  • .ngaterc.js

配置文件示例(JavaScript)

// ngate.config.js
module.exports = {
  // 服务器端口 (默认: 8080)
  port: 3000,
  
  // 静态文件目录 (默认: process.cwd())
  directory: './dist',
  
  // 是否启用gzip压缩 (默认: false)
  compress: true,
  
  // 是否启用CORS (默认: false)
  cors: true,
  
  // 缓存过期时间(秒)(默认: 3600,即1小时)
  cacheMaxAge: 86400, // 24小时
  
  // 代理规则 (默认: {})
  proxyRules: {
    '/api': 'http://localhost:8000',
    '/auth': 'http://localhost:9000'
  },
  
  // 是否自动打开浏览器 (默认: false)
  openBrowser: true
};

配置文件示例(JSON)

{
  "port": 3000,
  "directory": "./dist",
  "compress": true,
  "cors": true,
  "cacheMaxAge": 86400,
  "proxyRules": {
    "/api": "http://localhost:8000",
    "/auth": "http://localhost:9000"
  },
  "openBrowser": true
}

在NPM脚本中使用

可以在package.json的scripts中配置:

{
  "scripts": {
    "serve": "ngt -d ./dist -p 3000 --open"
  }
}

在代码中使用

ngate也可以作为模块在代码中使用:

const { ServerManager } = require('ngate');

const server = new ServerManager({
  port: 3000,
  directory: './public',
  compress: true,
  cors: true,
  cacheMaxAge: 3600,
  proxyRules: {
    '/api': 'http://localhost:8000'
  },
  openBrowser: true
});

server.start();

使用TypeScript:

import { ServerManager } from 'ngate';

const server = new ServerManager({
  port: 3000,
  directory: './public',
  compress: true,
  cors: true,
  cacheMaxAge: 3600,
  proxyRules: {
    '/api': 'http://localhost:8000'
  },
  openBrowser: true
});

server.start();

// 优雅地关闭服务器
process.on('SIGINT', () => {
  server.stop();
  process.exit(0);
});

兼容性

ngate 要求 Node.js 12.0.0 或更高版本。

贡献

欢迎通过 issue 和 pull request 贡献代码。

许可证

MIT