Last change
on this file since 76712b2 was 6a3a178, checked in by Ema <ema_spirova@…>, 3 years ago |
initial commit
|
-
Property mode
set to
100644
|
File size:
1.1 KB
|
Rev | Line | |
---|
[6a3a178] | 1 | killable
|
---|
| 2 | ========
|
---|
| 3 |
|
---|
| 4 | Keeps track of a server's open sockets so they can be destroyed at a
|
---|
| 5 | moment's notice. This way, the server connection can be killed very
|
---|
| 6 | fast.
|
---|
| 7 |
|
---|
| 8 | Installation
|
---|
| 9 | ------------
|
---|
| 10 |
|
---|
| 11 | ```
|
---|
| 12 | npm install killable
|
---|
| 13 | ```
|
---|
| 14 |
|
---|
| 15 | Example usage
|
---|
| 16 | -------------
|
---|
| 17 |
|
---|
| 18 | Using express:
|
---|
| 19 | ('server' in the example is just an ``http.server``, so other frameworks
|
---|
| 20 | or pure Node should work just as well.)
|
---|
| 21 |
|
---|
| 22 | ```javascript
|
---|
| 23 | var killable = require('killable');
|
---|
| 24 |
|
---|
| 25 | var app = require('express')();
|
---|
| 26 | var server;
|
---|
| 27 |
|
---|
| 28 | app.route('/', function (req, res, next) {
|
---|
| 29 | res.send('Server is going down NOW!');
|
---|
| 30 |
|
---|
| 31 | server.kill(function () {
|
---|
| 32 | //the server is down when this is called. That won't take long.
|
---|
| 33 | });
|
---|
| 34 | });
|
---|
| 35 |
|
---|
| 36 | var server = app.listen(8080);
|
---|
| 37 | killable(server);
|
---|
| 38 | ```
|
---|
| 39 |
|
---|
| 40 | API
|
---|
| 41 | ---
|
---|
| 42 |
|
---|
| 43 | The ``killable`` module is callable. When you call it on a Node
|
---|
| 44 | ``http.Server`` object, it will add a ``server.kill()`` method on it. It
|
---|
| 45 | returns the server object.
|
---|
| 46 |
|
---|
| 47 | ``server.kill([callback])`` closes all open sockets and calls
|
---|
| 48 | ``server.close()``, to which the ``callback`` is passed on.
|
---|
| 49 |
|
---|
| 50 | Inspired by: http://stackoverflow.com/a/14636625
|
---|
| 51 |
|
---|
| 52 | License
|
---|
| 53 | -------
|
---|
| 54 |
|
---|
| 55 | ISC
|
---|
Note:
See
TracBrowser
for help on using the repository browser.