@frangio/servbot

中文文档
0.3.0-1发布于 2025/06/06MITTypeScriptESM + CJS零依赖近 30 天下载 7000

A small dev server script for local static site development

原始使用文档
文档目录4 节
  1. Install
  2. Usage
  3. Using manual reload
  4. To-Do

servbot

A small dev server for local static site development. Essentially a wrapper around http.Server. Fork of servor.

import servbot from 'servbot';

const server = servbot({
    root: './public/',
    reload: true,
    fallback: 'index.html'
});

server.listen(8080);

This is an opinionated fork with some intentional exclusions and smaller scope, and some ideas taken from nativew/serve.

Install

npm install servbot --save-dev

Usage

See types in index.d.ts. servbot accepts a single argument, ServbotOptions; and returns an instance of ServbotServer. See below for the default options.

import servbot from 'servbot';

const server = servbot({
    // root: string
    // Directory to serve. Relative to process.cwd().
    root: '.',

    // reload: boolean
    // Flag to enable manual reload.
    reload: false,

    // fallback: string
    // Filename to fallback to for single-page applications. Relative to `root`.
    // Leaving this empty assumes you are not serving a single-page application
    fallback: '',

    // ignores: RegExp[]
    // *Only applicable when `fallback` is provided and `ignores` is not an empty array*.
    // A list of patterns to *not* route to your fallback.
    // Useful when you want to be able to route non-filetypes to your SPA ("/foo/routename.hi")
    // But otherwise, want to "ignore" routes that should be static files ("/main.css", "/js/jquery.js")
    ignores: [],

    // credentials: object
    // TLS Credentials. Providing these enables an HTTPS server.
    // See https://nodejs.org/api/https.html#httpscreateserveroptions-requestlistener
    credentials: undefined,

    // verbose: boolean
    // Flag to enable server response logging.
    verbose: true
});

// Start server on port 8080
server.listen(8080);

// Close server from new connections
// https://nodejs.org/api/net.html#serverclosecallback
server.close((err) => {
    if (err) process.exit();
});

Using manual reload

Instead of including a filewatcher to automatically reload your app on file changes, servbot includes a manual reload feature. Most modern front-end development build tools already include a built-in watch feature (esbuild, rollup, webpack, parcel, etc.) that can be leveraged by servbot. For an example with rollup, see here.

Outside of build tools, you can also use something like cheap-watch or watchlist. See below for an example using watchlist:

import servbot from 'servbot';
import { watch } from 'watchlist';

const server = servbot({
    root: './example/static/',
    reload: true,
    fallback: 'index.html'
});

server.listen(8080);

(async () => {
    await watch(['./example/static/'], async () => {
        console.log('change detected! reloading...');
        server.reload();
    });
})();

To-Do

  • Better tests for SPA example
  • HTTP/2 support

版本与发布记录

@frangio/servbot 共发布 4 个版本,首次发布于 2022/09/18;过去 12 个月发布了 0 个版本。

版本发布日期距今
0.3.0-1latest2025/06/061.4 年前
0.3.0-0next2022/11/024 年前
0.2.52022/09/184 年前
0.2.42022/09/184 年前

关于 @frangio/servbot 的常见问题

@frangio/servbot 是什么?

A small dev server script for local static site development

如何安装 @frangio/servbot?

在项目目录运行 npm install @frangio/servbot,或使用 pnpm add / yarn add / bun add。

@frangio/servbot 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@frangio/servbot 支持 ESM 还是 CommonJS?

同时提供 ES Module 与 CommonJS 入口,import 和 require() 都可以使用,打包工具会自动选择合适的版本。

@frangio/servbot 需要什么版本的 Node.js?

package.json 的 engines 字段要求 Node.js >=12.x。版本不符时 npm 默认只给出警告,开启 engine-strict 后会拒绝安装。

@frangio/servbot 可以商用吗?

@frangio/servbot 使用 MIT 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。以上为概括,不构成法律意见,请以许可原文为准。

@frangio/servbot 的下载量有多少?

根据 npm 官方下载统计,@frangio/servbot 在 2026/10/16 – 2026/11/14 这 30 天内被下载 7,000 次,日均约 233 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@frangio/servbot 还在维护吗?

最新版本 0.3.0-1 发布于 2025/06/06(1.4 年前);至今共发布 4 个版本,其中过去 12 个月发布了 0 个;首次发布于 2022/09/18。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。