node-static

node-static has an in-memory file cache, making it highly efficient.
node-static understands and supports conditional GET and HEAD requests.
node-static was inspired by some of the other static-file serving modules out there,
such as node-paperboy and antinode.

With this method, you don't have to explicitly send the response back, in case of an error.

Options when creating an instance of Server

cache

Sets the Cache-Control header.

example: { cache: 7200 }

Passing a number will set the cache duration to that number of seconds.
Passing false will disable the Cache-Control header.

Defaults to 3600

serverInfo

Sets the Server header.

example: { serverInfo: "myserver" }

Defaults to node-static/{version}

headers

Sets response headers.

example: { 'X-Hello': 'World!' }

defaults to {}

gzip

Enable support for sending compressed responses. This will enable a check for a
file with the same name plus '.gz' in the same folder. If the compressed file is
found and the client has indicated support for gzip file transfer, the contents
of the .gz file will be sent in place of the uncompressed file along with a
Content-Encoding: gzip header to inform the client the data has been compressed.

example: { gzip: true }
example: { gzip: /^\/text/ }

Passing true will enable this check for all files.
Passing a RegExp instance will only enable this check if the content-type of the
respond would match that RegExp using its test() method.

Defaults to false

Command Line Interface

node-static also provides a CLI.

Installation

$ npm install -g node-static

Example Usage

# serve up the current directory
$ static
serving "." at http://127.0.0.1:8080# serve up a different directory
$ staticpublic
serving "public" at http://127.0.0.1:8080# specify additional headers (this one is useful for development)
$ static -H '{"Cache-Control": "no-cache, must-revalidate"}'
serving "." at http://127.0.0.1:8080# set cache control max age
$ static -c 7200
serving "." at http://127.0.0.1:8080# show help message, including all options
$ static -h