node package manager


start-server: a command-line http server mock tools

start-server 是一个简单的http服务器,既可以是一个静态文件服务器,也可以是一个mock的api服务端,还支持类似CI框架的dcm的query来mock文件,在http-server基础上改写而来。


Installation via npm:

 npm install start-server -g


  • 启动服务器:

    start-server [path] [options]

    [path] defaults to ./mocks if the folder exists, and ./ otherwise.

    Now you can visit http://localhost:8899 to view your server

  • 根据现有的url创建一个静态文件(如果能请求到则使用请求的,如果不能则只创建一个文件):

    start-server mock url [options]



    start-server mock



module.exports = {
    'routes': {
        'all': {
            '/api/path1/path2': {

Available Options:

--config 指定配置文件地址(可选),默认[path]/config.js

-p Port to use (defaults to 8080)

-a Address to use (defaults to

-d Show directory listings (defaults to 'True')

-i Display autoIndex (defaults to 'True')

-g or --gzip When enabled (defaults to 'False') it will serve ./public/some-file.js.gz in place of ./public/some-file.js when a gzipped version of the file exists and the request accepts gzip encoding.

-e or --ext Default file extension if none supplied (defaults to 'html')

-s or --silent Suppress log messages from output

--cors Enable CORS via the Access-Control-Allow-Origin header

-o Open browser window after starting the server

-c Set cache time (in seconds) for cache-control max-age header, e.g. -c10 for 10 seconds (defaults to '3600'). To disable caching, use -c-1.

-U or --utc Use UTC time format in log messages.

-P or --proxy Proxies all requests which can't be resolved locally to the given url. e.g.: -P

-S or --ssl Enable https.

-C or --cert Path to ssl cert file (default: cert.pem).

-K or --key Path to ssl key file (default: key.pem).

-r or --robots Provide a /robots.txt (whose content defaults to 'User-agent: *\nDisallow: /')

-h or --help Print this list and exit.

--pathQueryKeys 如果需要类CI的路由风格,可以在这里指定,默认是d,c,m,设置为false则关闭query风格的路由模式


Checkout this repository locally, then:

$ npm i
$ node bin/http-server

Now you can visit http://localhost:8080 to view your server

You should see the turtle image in the screenshot above hosted at that URL. See the ./public folder for demo content.