httpdir

2.1.0 • Public • Published

Version Downloads Last commit Test Codecov Install Size

Icon

Simple, zero dependency command-line HTTP server for static local files

Safari window with a list of files


Installation

This module needs Node >=14.

Install with npm:

$ npm install httpdir --global

Usage

CLI

httpdir <path> <port>

Example:

# This will start a local server on port `8090`,
# with `~/Desktop` as root directory
httpdir ~/Desktop 8090

Default path is ., default port is 8080.

Node module

Import httpdir and create a server:

const httpdir = require('httpdir')
const server = httpdir.createServer({
  basePath: '/some/path', // Optional, default is "."
  httpPort: 9898,         // Optional, default is 8080
})

Main events can be listened to:

server.onStart((settings) => {
  console.log('Server started')
  console.log('Base path is:', settings.basePath)
  console.log('Port is:', settings.httpPort)
  console.log('Available URLs:', settings.urls.join(', '))
})
server.onStop(() => {
  console.log('Server stopped')
})
server.onResponse((response) => {
  console.log('Requested path was:', response.requestedPath)
  console.log('Requested method was:', response.requestedMethod)
  console.log('Response code is:', response.httpCode)
})
server.onError((error) => {
  console.log('Server error', error)
})

After event listeners have been attached if needed, start the server:

server.start()

And stop:

server.stop()

Changelog

This project uses semver.

Version Date Notes
2.1.0 2023-1-07 Support Range request header
2.0.1 2023-02-12 Fix onResponse event for favicons
2.0.0 2023-02-04 Expose node module
Drop Node 12 support
1.4.0 2023-01-29 Improve startup info
1.3.0 2023-01-28 Support more mime types
1.2.0 2022-01-10 Update UI (#1)
1.1.0 2021-09-25 Stop relying on deprecated url.parse()
1.0.1 2021-07-04 Fix execution issue on Unix
1.0.0 2021-07-04 Initial version

License

This project is released under the MIT License.

Package Sidebar

Install

npm i httpdir

Weekly Downloads

10

Version

2.1.0

License

MIT

Unpacked Size

32.5 kB

Total Files

16

Last publish

Collaborators

  • johansatge