httpe

The HTTP interface designed to support http & https protocols & multiple ports simultaneously.

Source:

Members

(inner) IncomingMessage

Source:
Implements:

Creates the request object used to access client status, headers and data. See IncomingMessage.

(inner) Server

Source:
Implements:

Creates a new HTTP & HTTPS Server that supports multiple ports. See Server.

Example

Create a server on port 8080 that is automatically listening

server = new httpe.Server({ port: 8080, listen: true })

(inner) ServerResponse

Source:
Implements:

Creates the response object used to define server status, headers and data. See ServerResponse.

Methods

(inner) createServer(optionsopt, connectionListeneropt) → {Server}

Source:

Creates a new HTTP & HTTPS Server that supports multiple ports.

Example

Create a server on port 8080 that is automatically listening

server = new httpe.createServer({ port: 8080, listen: true })
Parameters:
Name Type Attributes Description
options Object <optional>

The options for the server or connectionListener.

Properties
Name Type Attributes Description
useAvailablePort Boolean <optional>

Whether to use the first available port from the desired port or ports.

listen Boolean <optional>

The overriding desired port or ports to use if they are available, otherwising using the first available.

port Array | Number <optional>

The desired port or ports to use.

cert Buffer | String <optional>

The certificate; when missing along with options.key will cause a new certificate to be generated.

key Buffer | String <optional>

The key; when missing along with options.cert will cause a new certificate to be generated.

connectionListener function <optional>

The listener bound to all connections.

Returns:
Type
Server

(inner) generateCertificate(props, opts) → {Object}

Source:

Generates a new SSL certificate.

Example
cert = new httpe.generateCertificate({
  commonName: 'example.org',
  countryName, 'US',
  localityName: 'Blacksburg',
  organizationName: 'Test'
})
Parameters:
Name Type Description
props Array | Object

A map of OID subject items.

opts Object

Additional certificate configuration.

Returns:

The certificate (cert) and private key (key).

Type
Object

(inner) getCharset(path) → {String|Null}

Source:

Returns the character set of a given path.

Example
httpe.getCharset('/script.js') // 'UTF-8'
Parameters:
Name Type Description
path String

The path used to determine the charset.

Returns:

The determined charset set or null.

Type
String | Null

(inner) getContentType(path) → {String|Null}

Source:

Returns the content type of a given path.

Example
httpe.contentType('/script.js') // 'application/javascript; charset=utf-8'
Parameters:
Name Type Description
path String

The path used to determine the content-type.

Returns:

The determined content-type or null.

Type
String | Null

(inner) getMimeType(path) → {String|Null}

Source:

Returns the mime type of a given path.

Example
httpe.getCharset('/script.js') // 'application/javascript'
Parameters:
Name Type Description
path String

The path used to determine the mimetype.

Returns:

The determined mimetype or null.

Type
String | Null

(async, inner) getPathStats(path, optsopt) → {Stats}

Source:

Returns the file stats for a given path.

Example
httpe.getPathStats('/path/to/dir').then(stats => {
  // get the resolved path
  const isPathAFile = stats.path

  // get whether the path is a file
  const isPathAFile = stats.isFile()

  // destructure additional custom stats
  const { charset, contentLength, contentType, lastModified, mimeType, path } = stats
})
Parameters:
Name Type Attributes Description
path String

The path used to get stats.

opts Object <optional>

Additional configuration resolving file stats.

Properties
Name Type Attributes Default Description
from Object <optional>
'.'

The directory used to resolve the path.

index Object <optional>
'index.html'

The index basename used to resolve directories.

Returns:

A promise resolving with the matching path and file stats, or an error if it failed.

Type
Stats

(async, inner) isPortAvailable(port, useAvailablePort) → {Number|Error}

Source:

Returns a promise for whether a port is available for a connection.

Examples
httpe.isPortAvailable(80).then(availablePort => {}, error => {});

Get any available port from 80 onward

httpe.isPortAvailable(80, true).then(availablePort => {}, error => {});
Parameters:
Name Type Description
port Number

The port tested for an available connection.

useAvailablePort Boolean

Whether to use the first available port.

Returns:

A promise resolving with the available port or rejecting with the error.

Type
Number | Error