Constructor
new Server(optionsopt, connectionListeneropt) → {Server}
Example
server = new Server({ port: 8080, listen: true })
Parameters:
Name | Type | Attributes | Description | ||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
options |
Object |
<optional> |
The options for the server or Properties
|
||||||||||||||||||||||||||||
connectionListener |
function |
<optional> |
The listener bound to all connections. |
Returns:
- Type
- Server
Extends
- https.Server
Members
listening :Boolean
Returns whether the server is currently listening.
Type:
- Boolean
Example
server.listening // true or false
port :Array
Returns or assigns the ports currently being requested.
Type:
- Array
Examples
server.port // [80, 443]
server.port = 80
server.port // [80]
Methods
close(closeListeneropt) → {Server}
Stops the server from accepting new connections.
Example
server.close(() => {
console.log(`httpe has closed…`)
})
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
closeListener |
function |
<optional> |
The method called when all of the servers have been unbound. |
Returns:
- Type
- Server
listen(optionsopt, listeneropt) → {Server}
Starts a server listening for connections.
Example
server.listen(() => {
console.log(
`httpe is listening…\n` +
`--------------------------------------\n` +
` Local: ${server.port.map(port => `http://localhost:${port}/`).join('\n ')}\n` +
`External: ${server.port.map(port => `http://${httpe.ip}:${port}/`).join('\n ')}\n` +
`--------------------------------------`
)
})
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
options |
function | Options | Port |
<optional> |
The port used for connections, the options for the server, or the listener called once the server is bound. |
listener |
function |
<optional> |
The listener called once the server has been bound. |
Returns:
- Type
- Server
use(patternopt, callbackopt) → {Server}
Attach visitor functions on requests to the server.
Examples
server.use((req, res) => {
// do something with any request
})
server.use('/\**.js', (req, res) => {
// do something with any request ending in .js
})
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
pattern |
Object | String | RegExp |
<optional> |
The pattern used to match requests. |
callback |
function |
<optional> |
The method called whenever a request is made and/or matched. |
Returns:
- Type
- Server