#overshadow-listeners

Add an event listener before existing listeners.
Why
Event listeners always fire in the order they are added, yet sometimes we have no control over
this ordering and require certain listeners to definitely run before any others.
Example
var http = require('http')
var Overshadow = require('overshadow-listeners')
var server = http.createServer(function(req, res) {
res.end('ok!')
})
Overshadow(server).on('request', function(req, res) {
if (req.url !== '/') return res.end('no.')
})
Overshadow(server).once('request', function(req, res) {
})
server.listen(9000)
detach/reattach
Alternatively, manually detach and reattach listeners:
var overshadow = Overshadow(server)
overshadow.detach('request')
server.on('request', function(req, res) {
if (req.url !== '/') return res.end('no.')
})
overshadow.reattach('request')
detach/reattach is chainable
We've included a simple .then(fn) method you can call to make chainable the process of detaching, doing something then reattaching. .then(fn) does nothing but execute the supplied function
Overshadow(server)
.detach('request')
.then(function() {
server.once('request', function(req, res) {
if (req.url !== '/') return res.end('no.')
})
})
.reattach('request')
Also See
Licence
MIT