Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 5 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,21 +49,12 @@ then curl it:
curl http://localhost:<port>
```

## Setting listening port
## Command line args

To set the http port, either supply the port as an argument to the
`http-echo-server` executable:

```
http-echo-server 3005
```

Or use the `PORT` environment variable:

```
export PORT=3005
http-echo-server
```
| arg | description |
| - | - |
| `--port` or `-p` | The port to listen on (default: 3000) |
| `--delay` or `-d` | The delay before returning (default: 2000) |

## License

Expand Down
18 changes: 16 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,20 @@

var getPort = require('get-port')
var server = require('net').createServer()
const argv = require('yargs')
.option('port', {
alias: 'p',
type: 'number',
description: 'The port to listn on'
})
.option('delay', {
alias: 'd',
type: 'number',
description: 'Delay before returning connection (ms)',
default: 2000
})
.argv
const util = require('util')

var cid = 0

Expand Down Expand Up @@ -42,7 +56,7 @@ server.on('connection', function (c) {
c.write('\r\n')
setTimeout(function () {
c.end()
}, 2000)
}, argv.delay)
}
c.write(chunk.toString())
})
Expand All @@ -61,7 +75,7 @@ server.on('error', function (err) {
console.log('[server] event: error (msg: %s)', err.message)
})

var port = process.argv[2] || process.env.PORT
var port = argv.port || process.env.PORT

if (port) {
server.listen(port)
Expand Down
Loading