Skip to content

The easiest way to create http, http2, https, https2, tcp, tls, udp servers in Node.js

License

Notifications You must be signed in to change notification settings

awesomeorganization/servers

Repository files navigation

@awesomeorganization/servers

💥 [ESM] The easiest way to create http, http2, https, https2, tcp, tls, udp servers in Node.js


GitHub Workflow Codacy CodeFactor Snyk Depfu npms.io


Install

npm install @awesomeorganization/servers

Example

Full example in /example folder.

import { LOCALHOST_CERT, LOCALHOST_KEY, http, https, https2 } from '@awesomeorganization/servers'

const example = () => {
  http({
    handlers: {
      request(_request, response) {
        response.end('Hi!')
      },
    },
    listenOptions: {
      host: '127.0.0.1',
      port: 3000,
    },
  })
  https({
    createOptions: {
      cert: LOCALHOST_CERT,
      key: LOCALHOST_KEY,
    },
    handlers: {
      request(_request, response) {
        response.end('Hi!')
      },
    },
    listenOptions: {
      host: '127.0.0.1',
      port: 4000,
    },
  })
  https2({
    createOptions: {
      cert: LOCALHOST_CERT,
      key: LOCALHOST_KEY,
    },
    handlers: {
      stream(stream) {
        stream.end('Hi!')
      },
    },
    listenOptions: {
      host: '127.0.0.1',
      port: 5000,
    },
  })
}

example()

// TRY
// http://127.0.0.1:3000/
// https://127.0.0.1:4000/
// https://127.0.0.1:5000/