simplatic-http-server
TypeScript icon, indicating that this package has built-in type declarations

1.1.1 • Public • Published

npm (scoped) Dependencies Status devDependencies Status Known Vulnerabilities install size
Coverage Status
Commitizen friendly GitHub forks GitHub stars
GitHub

Simple Static Http Server

A very light-weight and very simple static HTTP server based on node.js's built-in http module


Installation

npm install simplatic-http-server

Usage

  1. Get access to the main class:

    const StaticServer = require('simplatic-http-server').default

    Or:

    import StaticServer from 'simplatic-http-server'
  2. Instantiate:

    const staticServer = new StaticServer(portNumber /*, servePath = process.cwd() */) 
  3. Listen to portNumber:

    await staticServer.listen(/* onListenCallback, onErrorCallback */)
     
    console.log(`The static server listening on ${portNumber} ...`)

    Or:

    staticServer.listen().then(
        () => console.log(`The static server listening on ${portNumber} ...`), 
        err => console.error(err)
    )
  4. Get access to a file in servePath. E. g. type in your browser's address bar: http://127.0.0.1/dir/index.html (Note: The path of index.html must be `${servePath}/dir/index.html` on your local machine).

  5. Turn it off when no more needed:

    await staticServer.shutdown(/* callback */)

/simplatic-http-server/

    Package Sidebar

    Install

    npm i simplatic-http-server

    Weekly Downloads

    3

    Version

    1.1.1

    License

    MIT

    Unpacked Size

    12.4 kB

    Total Files

    5

    Last publish

    Collaborators

    • mirismaili