This package has been deprecated

Author message:

replaced by httpservice

@mangar2/httpserver

1.2.1 • Public • Published

Abstract

This is a very simple web server. It is based on the http packet included in node.js. I built it due to its simplicity and the independence from other packages

Functionality

constuct the server with new Server(port number). register your callbacks according to the http functions you need. Supported are put, patch, get, post, delete (it does not matter, if you use upper or lower case letters) All those functions receives 4 parameters:

  • payload: the data sent (body)
  • headers: the http header structure
  • path: the path as string
  • res: the http res structure

Usage example

server = new HttpServer(9001); server.on('get', (payload, headers, path, res) => { console.log('get received'); console.log(payload); console.log(headers); console.log(path); res.writeHead(200, {'Content-Type': 'text/plain'}); res.end("get"); });

listen and closed callbacks

The web server additionally supports the callbacks "listen" and "closed" called, once the server is listening and once the server is closed. Both callbacks have no parameters.

close

The server has a close function that closes all active socket connections and shuts down the server.

Dependencies (2)

Dev Dependencies (0)

    Package Sidebar

    Install

    npm i @mangar2/httpserver

    Weekly Downloads

    0

    Version

    1.2.1

    License

    LGPL-3.0-or-later

    Unpacked Size

    9.16 kB

    Total Files

    4

    Last publish

    Collaborators

    • mangar2