Skip to content

http: add `http.createStaticServer`

Rodrigo Muino Tomonari requested to merge github/fork/aduh95/http-server into main

This PR adds a small utility to spawns a really simple HTTP 1.1 server to serve a local directory. The server is not meant to be secure or extremely performant, it's meant to be minimal and a useful replacement for python -m http.server. This should never be used in production of course.

Usage:

node -e 'http.createStaticServer()' # starts serving the cwd on a random port

# To start serving on the port 8080 using /path/to/dir as the root:
node -e 'http.createStaticServer({directory: "/path/to/dir", port: 8080})'

# Same as above, but exposing your local file system to the whole IPv4 network:
node -e 'http.createStaticServer({directory: "/path/to/dir", port: 8080, host: "0.0.0.0"})'

Semver-major if we want to release it without requiring the node: prefix. EDIT: I've removed the node:http/static module from this PR, it can be discussed in a separate PR.

Fixes: https://github.com/nodejs/node/issues/45079

Merge request reports

Loading