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 🙏

© 2024 – Pkg Stats / Ryan Hefner

socket-input-params

v1.0.2

Published

A Node.js module used to receive input parameters via a Unix domain socket.

Downloads

5

Readme

Socket Input Params

A Node.js module used to receive input parameters via a Unix domain socket.

Rationale

This module has been put together to work around a limitation of the Meteor platform that (as of this writing) does not provide a way for input parameters to be passed to the target (server) application.

It is also useful for passing sensitive data like passwords to running applications, and avoid them to be accidentally disclosed if other, more conventional mechanisms like command line arguments and environment variables are used.

How It Works

The module opens a Unix domain socket named inputparams in the current work directory, and waits for data to be received through it. The received data is then parsed, and the resulting command line options are returned to the calling application.

Installation

npm install socket-input-params

Usage

Instantiate the socket input parameters object.

const SocketInputParams = require('socket-input-params');

const sockInParams = new SocketInputParams({
    readTimeout: 30000,
    optionDefs: [{
        name: 'password',
        alias: 'p'
    }]
});

Constructor options

The following options can be used when instantiating the socket input parameters object:

  • path [String] - (optional, default: '.') Path where the Unix domain socket should be created.
  • socketName [String] - (optional, default: 'inputparams') Name of the Unix domain socket to be created.
  • readTimeout [Number] - (optional, default: 60000) Timeout, in milliseconds, for reading data from the Unix domain socket.
  • optionDefs [Array | Object] - List of objects defining the command line options to be expected as input parameters as defined by the 'command-line-args' Node.js module. When defining a single option, an object can be passed instead of an array.

Retrieve command line options

Using a callback

sockInParams.getCommandLineOptions((err, result) => {
    if (err) {
        console.error('Error retrieving command line options', err);
    }
    else {
        console.log('Retrieved command line options', result);
    }
})

Using promise

sockInParams.getCommandLineOptions()
.then(result => {
    console.log('Retrieved command line options', result);
})
.catch(err => {
    console.error('Error retrieving command line options', err);
});

Sample returned command line options

{
    password: '123456'
}

Note: for more examples of how command line options are returned, please refer to the 'command-line-args' Node.js module.

Passing parameters to the running application

The following is a sample shell script that can be used to pass input parameters (via Unix domain socket) to a running application (that makes use of this module).

#!/bin/bash
# Script used to send input parameters to running application via Unix domain socket
#
# How to use it:
#  . any parameters to be passed should be preceded by '--'
#  . if no password parameter is passed (-p <psw>) the script will ask for a password to be entered

cd "$APP_DIR"

# Filter internal (before '--') and external (after '--') parameters
idx=0
delimiterFound=0
hasPswOption=0

for arg; do
  if [ $delimiterFound -eq 1 ]; then
    # Save external parameter (to be passed to running application)
    extParams[idx]="$arg"

    if [[ $arg == "-p" || $arg == "--password" ]]; then
      hasPswOption=1
    fi
  else
    if [ $arg == "--" ]; then
      delimiterFound=1
    else
      # Save internal parameter (to be interpreted by this script)
      intParams[idx]="$arg"
    fi
  fi

  ((idx++))
done

if [ $hasPswOption -ne 1 ]; then
  # Request user to enter password (to be passed to running application)
  echo -n "Enter password: "
  read -s psw
  echo

  # Add password to external parameters
  extParams[idx]="-p"
  ((idx++))
  extParams[idx]="$psw"
fi

tmout=60

# Wait for Unix domain socket used to input parameters to be created (by running application)
while [ ! -S ./inputparams ]; do
  if [ $tmout -eq 0 ]; then
    echo "Timeout waiting for input parameters socket"
    exit -1
  fi
  sleep 1
  ((tmout--))
done

extParamsList=""

for param in "${extParams[@]}"; do
  extParamsList="$extParamsList '$param'"
done

# Send external parameters to running application (through open Unix domain socket)
echo -n "$extParamsList" | nc -U ./inputparams

Note: it is assumed that the environment variable $APP_DIR contains the path of the directory where the Unix domain socket created by the running application is located.

License

This Node.js module is released under the MIT License. Feel free to fork, and modify!

Copyright © 2020, Blockchain of Things Inc.