javascript - return value from one function to other -
im using following code , question how should pass port first function seconde,i know if call second function inside first can there other way parctise use?
portscanner.findaportnotinuse(3000, 3010, '127.0.0.1', function(error, port) { console.log('available port at: ' + port) }); http.createserver(function (req, res) { res.writehead(200, { 'content-type': 'text/plain' }); json.stringify(req.headers, true, 2)); res.end(); }).listen(9033);
instead of using port 9033 want use value first...
the port scanner method asynchronous, way create server when available port has been determined, when callback function called:
portscanner.findaportnotinuse(3000, 3010, '127.0.0.1', function(error, port) { console.log('available port at: ' + port) http.createserver(function (req, res) { // ... }).listen(port); });
Comments
Post a Comment