eport

0.1.2 • Public • Published

eport Build Status

Find a free port

Install

Install this package with npm, if you have not install NodeJs or npm, you should install that first.

   npm install eport --save-dev

Just run this commands to install eport for your project.

Usage

  var eport = require('eport');
  eport([host], function(error, port) {
    // do something with the port.
  });

Method

require('eport')([host], callback);

  • [host] A hostname or ip address that it will listen to.
  • callback(error, port) A hostname or ip address that it will listen to.
    • callback.error object throws error
    • callback.port number a free port.

Example 1

eport("127.0.0.1", function(error, port) {
  if (!error) {
    // Now listening to the port of second arguments
  }
});
 
// without host
eport(function(error, port) {
  // ...
});
 

Example 2

 
 // Set a random port for livereload;
  grunt.registerTask('setServerPort', function() {
    var eport = require('eport');
    var done = this.async();
 
    // grunt server port;
    eport(function(error, port) {
      if (!error) {
        grunt.config.set('connect.options.livereload', port);
      } else {
        grunt.log.error(error);
      }
      done();
    });
  });

Package Sidebar

Install

npm i eport

Weekly Downloads

3

Version

0.1.2

License

ISC

Last publish

Collaborators

  • colin-luo