npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2025 – Pkg Stats / Ryan Hefner

react-native-portavailable

v1.0.1

Published

A React Native Package for checking udp & tcp port availability on native android

Downloads

40

Readme

react-native-portavailable

A React Native Package for checking tcp and udp port availability on native android.

This is an implementation coming from the Apache camel project.

Support

This package is only supported on android devices, since i'm not much of an iOS Developer. The source code is pretty much straightforward so feel free to submit a PR of an iOS port i'll be happy to merge ! :)

Install

npm i -S react-native-portavailable

Android

  • Add the following line to the bottom of your project's settings.gradle file.

    project(':react-native-portavailable').projectDir = new File(settingsDir, '../node_modules/react-native-portavailable/android')

  • Change the include line of your project's settings.gradle to include the :react-native-portavailable project.

    include ':react-native-portavailable', ':app'

  • Open your app's build.gradle file and add the following line to the dependencies block.

    compile project(":react-native-portavailable")

  • In your app's MainActivity.java file, add new PortAvailableReactModule() to the return statement of the getPackages() function.

...
    new MainReactPackage(),
    new PortAvailableReactModule()
...
  • Then in the same file add the import statement : import com.odinvt.portavailable.PortAvailableReactModule;

Usage

import PortAvailable from 'react-native-portavailable'

API

The calls to PortAvailable methods are static so you can go ahead and use it directly.

Methods
PortAvailable.check(port) Checks if the port 'port' is available
  • This will return a Promise instance that resolves to a boolean of the availability of the port. We're handling sockets opened and closed on the native side so we do need to expect an async execution. There is no need to use a catch method on the Promise object since all the exceptions are caught on the native side and the Promise just resolves to false.

Example :


PortAvailable.check(48500).then(available => {
  // 'available' is true if the port 48500 is available
})
PortAvailable.checkRange(min_port, max_port, stop = 0) Checks which of the ports between 'min_port' and 'max_port' (included) are available
  • This will return a Promise instance that resolves to an array of the available ports.
  • The stop parameter is optional and tells the function at how much available ports it should stop checking and resolve. stop = 0 is the default value and it tells the function to just check all the ports until max_port.

Example :


PortAvailable.checkRange(48500, 48600, 5).then(ports => {
  // 'ports' is an array of the available ports
  // for example : ports = [48500, 48501, 48502, 48503, 48505] if 48504 is not available
})
PortAvailable.getPorts() Returns the ports discovered by the last checkRange method call
  • This will return an array of the available ports.
  • The preferred way of getting the discovered ports is inside the PortAvailable.checkRange then callback. This method is provided so you can access the discovered ports anywhere on your application but only if you're sure that the PortAvailable.getPorts() call is made after the PortAvailable.checkRange Promise resolves .

Example :


let open_ports = PortAvailable.getPorts();
// open_ports = [48500, 48501, 48502, 48503, 48505]

Babel

This component uses ES6. So if you're using Webpack you should launch babel on main.js and output to main-tf.js if for some reason the npm postinstall script didn't execute.

"postinstall": "babel main.js --out-file main-tf.js"