port-type

Categorize port numbers by semantics.

Usage no npm install needed!

<script type="module">
  import portType from 'https://cdn.skypack.dev/port-type';
</script>

README

port-type Build status for port-type on Circle CI.

Categorize port numbers by semantics.

Why?

  • Helps you screen user input.
  • Identify port ranges by name.
  • Can tell you if it is possible to start a server.

Install

npm install port-type --save

Usage

Get it into your program.

const portType = require('port-type');

Identify the type of port you are working with, as a lowercase string.

portType.is(123);  // => "system"

But why type all that and still have to do a strict equality check? Fuggedaboutit.

portType.isSystem(123);  // => true

There are other types, too.

const port = 4444;
portType.isSystem(port);      // => false
portType.isRegistered(port);  // => true
portType.isDynamic(port);     // => false

Still wondering what these are exactly? They are simple number ranges, which determine how different sets of ports should be used. You can get the definition of each range, too.

portType.range.system.min;      // => 1
portType.range.registered.max;  // => 49151

Eventually you will want to determine if it is even remotely possible or sensible to try to listen on a port.

const port = 80;
portType.needsRoot(port);   // => false on Windows, true everywhere else
portType.haveRights(port);  // => true on Windows, false everywhere else unless running as root

Isn't that warm and cozy? Just look at it.

Contributing

See our contributing guidelines for more details.

  1. Fork it.
  2. Make a feature branch: git checkout -b my-new-feature
  3. Commit your changes: git commit -am 'Add some feature'
  4. Push to the branch: git push origin my-new-feature
  5. Submit a pull request.

License

MPL-2.0 © Seth Holladay

Go make something, dang it.