javascript - Using BB promise to create server with free port -


when run create server & listen in unit test times i'm getting following error:

eaddrinuse,

now want handle using module portscanner find free port

i this

var http = require('http'); var promise = require('bluebird'); var portscanner = require('portscanner');  var server = http.createserver(function (req, res) {     if (req.url == '/fail') {         res.end("failed");     } else {         res.writehead(200, {"content-type": "text/plain"});     } });  promise.promisifyall(server);  server.listenasync(portscanner.findaportnotinuse)  module.exports = server; 

this working not sure if it's stable code

my question if it's ok use this? , not dirty workaround , if yes how can handle better?

not sure why using promise in case, can use :

portscanner.findaportnotinuse(3000, 5000, '127.0.0.1', (error, port) =>{     server.listen(port); }); 

Comments

Popular posts from this blog

unity3d - Rotate an object to face an opposite direction -

angular - Is it possible to get native element for formControl? -

javascript - Why jQuery Select box change event is now working? -