serve
    Overview
    Documentation
    Insights
    Code
    Contributors
    Dependencies
    Alternatives

serve

Static file serving and directory listing

11.1.0  •  Published 5 months ago  •  by zeit  •  MIT License

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

How do you feel about the name Devstore for this site?

Popularity

Weekly Downloads
192.9K
Stars
5.1K

Maintenance

Development

Last ver 5 months ago
Created 8 years ago
Last commit 2 months ago
2 days between commits

Technology

Node version: 10.16.0
16.3K unpacked

Compliance

MIT License
OSI Approved
0 vulnerabilities

Contributors

70 contributors
Leonard Lamprecht
Maintainer, 488 commits, 221 merges, 50 PRs
Works at zeit
greenkeeper[bot]
78 commits
Guillermo Rauch
Maintainer, 24 commits, 9 merges, 1 PRs
Works at https://zeit.co
greenkeeperio-bot
13 commits, 15 PRs
Works at greenkeeperio
Spenser Isdahl
8 commits, 8 PRs
Nathan Rajlich
3 commits, 3 merges, 2 PRs
Works at zeit

Tags

now
serve
micro
http-server
Ready for the next level?
Join Devstore's founding team to help us build the ultimate open-source app store, work with the latest technologies, and enjoy great culture, impact and autonomy
© 2019 Devstore, Inc.
Devstore helps developers find and use open-source packages, so they can focus on building amazing things