Socket
Socket
Sign inDemoInstall

requires-port

Package Overview
Dependencies
0
Maintainers
2
Versions
3
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    requires-port

Check if a protocol requires a certain port number to be added to an URL.


Version published
Weekly downloads
25M
increased by2.62%
Maintainers
2
Install size
9.11 kB
Created
Weekly downloads
 

Package description

What is requires-port?

The `requires-port` package is a simple utility used to determine if a default port is required for a given protocol. It's particularly useful when working with URLs or networking in Node.js applications, where you might need to append a port to a hostname based on the protocol being used. This package helps in making decisions about whether to include the port in a URL string.

What are requires-port's main functionalities?

Checking if a port is required for a protocol

This feature allows you to check if a specific port is typically required for a given protocol. For standard protocols like HTTP (80) and HTTPS (443), it returns `false` indicating that the port does not need to be explicitly mentioned in a URL since it's the default. For non-standard ports or protocols, it returns `true`, suggesting that the port should be specified. The code sample demonstrates how to use `requires-port` to check for common and custom protocols.

"use strict";\nconst requiresPort = require('requires-port');\n\n// Example for HTTP\nconsole.log(requiresPort(80, 'http')); // false\n\n// Example for HTTPS\nconsole.log(requiresPort(443, 'https')); // false\n\n// Example for a custom protocol\nconsole.log(requiresPort(8080, 'my-protocol')); // true"

Other packages similar to requires-port

Readme

Source

requires-port

Made by unshiftVersion npmBuild StatusDependenciesCoverage StatusIRC channel

The module name says it all, check if a protocol requires a given port.

Installation

This module is intended to be used with browserify or Node.js and is distributed in the public npm registry. To install it simply run the following command from your CLI:

npm install --save requires-port

Usage

The module exports it self as function and requires 2 arguments:

  1. The port number, can be a string or number.
  2. Protocol, can be http, http: or even https://yomoma.com. We just split it at : and use the first result. We currently accept the following protocols:
    • http
    • https
    • ws
    • wss
    • ftp
    • gopher
    • file

It returns a boolean that indicates if protocol requires this port to be added to your URL.

'use strict';

var required = require('requires-port');

console.log(required('8080', 'http')) // true
console.log(required('80', 'http'))   // false

License

MIT

Keywords

FAQs

Last updated on 30 Oct 2015

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc