zeit/serve


Static file serving and directory listing

https://zeit.co/blog/serve-7

License: MIT

Language: JavaScript

Keywords: cli, command, http, node


Build Status Install Size Join the community on Spectrum

Assuming you would like to serve a static site, single page application or just a static file (no matter if on your device or on the local network), this package is just the right choice for you.

It behaves exactly like static deployments on Now, so it's perfect for developing your static project. Then, when it's time to push it into production, you deploy it.

Furthermore, it provides a neat interface for listing the directory's contents:

screenshot

Usage

The quickest way to get started is to just run npx serve in your project's directory.

If you prefer, you can also install the package globally using Yarn (you'll need at least Node.js LTS):

yarn global add serve

Once that's done, you can run this command inside your project's directory:

serve

Finally, run this command to see a list of all available options:

serve --help

Now you understand how the package works! 🎉

Configuration

To customize serve's behavior, create a serve.json file in the public folder and insert any of these properties.

API

The core of serve is serve-handler, which can be used as middleware in existing HTTP servers:

const handler = require('serve-handler');
const http = require('http');

const server = http.createServer((request, response) => {
  // You pass two more arguments for config and middleware
  // More details here: https://github.com/zeit/serve-handler#options
  return handler(request, response);
})

server.listen(3000, () => {
  console.log('Running at http://localhost:3000');
});

NOTE: You can also replace http.createServer with micro, if you want.

Contributing

  1. Fork this repository to your own GitHub account and then clone it to your local device
  2. Uninstall serve if it's already installed: npm uninstall -g serve
  3. Link it to the global module directory: npm link

After that, you can use the serve command everywhere. Here's a list of issues that are great for beginners.

Credits

This project used to be called "list" and "micro-list". But thanks to TJ Holowaychuk handing us the new name, it's now called "serve" (which is much more definite).

Author

Leo Lamprecht (@notquiteleo) - ZEIT

Project Statistics

Sourcerank 19
Repository Size 906 KB
Stars 4,495
Forks 329
Watchers 50
Open issues 56
Dependencies 186
Contributors 65
Tags 138
Created
Last updated
Last pushed

Top Contributors See all

Leo Lamprecht greenkeeper[bot] Guillermo Rauch Greenkeeper Spenser Isdahl Federico Miras Matheus Fernandes Justin Toh James Kyburz Tara Vancil Mathias Bynens Tim Neutkens Djalma Araújo Boris Serdiuk Sébastien Lorber Giuseppe Vitaly Domnikov Pablo P Varela EGOIST Max Beatty

Packages Referencing this Repo

serve
Static file serving and directory listing
Latest release 11.1.0 - Updated - 4.5K stars
serve-esm
Static file serving and directory listing
Latest release 1.0.0 - Published - 4.5K stars
serve-qrcode
Static file serving and directory listing
Latest release 11.0.2 - Published - 4.5K stars
list-seb
Single-command HTTP directory listing and file serving
Latest release 0.8.3 - Updated - 4.5K stars
awjre-test
Static file serving and directory listing
Latest release 0.1.0 - Updated - 4.5K stars
sharing
快速文件服务器
Latest release 1.0.7 - Updated - 4.5K stars
new-serve
Static file serving and directory listing
Latest release 6.4.3 - Updated - 4.5K stars
serve-noport
Static file serving and directory listing
Latest release 1.0.0 - Published - 4.5K stars
micro-list
Single-command HTTP directory listing and file serving
Latest release 0.8.0 - Updated - 4.5K stars
@leancloud/serve
Static file serving and directory listing
Latest release 9.4.0 - Published - 4.5K stars
@compass-rose/serve
Static file serving and directory listing
Latest release 1.0.2 - Updated - 4.5K stars
serve-testing
Static file serving and directory listing
Latest release 6.5.11 - Updated - 4.5K stars
awjr-npm-test
Static file serving and directory listing
Latest release 0.0.1 - Published - 4.5K stars

Recent Tags See all

11.1.0 July 10, 2019
11.0.2 June 19, 2019
11.0.1 May 28, 2019
11.0.0 April 03, 2019
10.1.2 February 06, 2019
10.1.1 November 12, 2018
10.1.0 November 12, 2018
10.0.2 September 24, 2018
10.0.1 September 12, 2018
10.0.0 August 21, 2018
9.6.0 August 14, 2018
9.5.0 August 14, 2018
9.4.2 August 09, 2018
9.4.1 August 09, 2018
9.4.0 July 25, 2018

Interesting Forks See all

dotcypress/micro-list
Single-command HTTP directory listing and file serving
JavaScript - Last pushed - 2 stars

Something wrong with this page? Make a suggestion

Last synced: 2019-07-10 01:53:46 UTC

Login to resync this repository