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

middleware-remoteshell

v1.0.1

Published

allow developers to tail logs remotely using curl (and run cmds) in express/polka/http

Downloads

2

Readme

express remoteshell

allow developers to tail logs remotely using curl (and run cmds):

$ node test/polka.js 
[rshell] for terminal access run: $ curl -sSNT. localhost:8080 -u username:password
> Running on localhost:3000

$ curl <someurl>
welcome..beep..boop

myapp $ ls
stdout
stderr
myapp $ stdout
23-01 13:10:12 log: hello world from console.log

Usage

app.js:

const polka = require('polka');
const port = 8080
 
const rshell = require('middleware-remoteshell')({
    port,
    welcome:  `welcome..beep..boop..\n\n`,
    prompt: 'myapp $ ', 
    userpass: (process.env.RSHELL_USERS||'').split(","),
    allowed: (req,res) => String(req.headers['user-agent']).match(/curl\//) && rshell.userpass.length, 
    interactive: true,
    oncmd: (i) => {
        let error = null
        let cmd   = i.cmd.trim()
        if( cmd.match(/(stderr|stdout)/) ){
            rshell.clients[i.id][cmd] = !rshell.clients[i.id][cmd]
            if( cmd == 'stdout' ) return i.cb(error, 'stdout toggled')
            if( cmd == 'stderr' ) return i.cb(error, 'stderr toggled')
        }
        if( cmd == 'ls'     ) return i.cb(error, 'stdout\nstderr')
        i.cb(error, "unknown cmd: "+i.cmd)
    }
})
rshell.start()

app.use( rshell.middleware )
// see test/polka.js or test/express.js for the full picture 

Host it somewhere

Only host this locally, or through an SSL proxy, SSH tunnel or intranet. Simple HTTP allows password sniffing (oops!) .

$ RSHELL_USERS="admin:admin,john:doe" node app.js
listening at 8080
[rshell] for terminal access run: $ curl -sSNT. localhost:8080 -u admin:admin

Meanwhile somewhere else

$ curl -sSNT. localhost:8080 -u admin:admin 

$ alias myapp="curl -sSNT. localhost:8080 -u admin:admin | stdbuf -i0 -o0 -e0 tr -d '\000'"

welcome..beep..boop..

01-28 15:45:45 log: test
01-28 15:45:45 err: this is an example error
01-28 15:45:46 log: test
01-28 15:45:46 err: this is an example error
01-28 15:45:47 log: test
01-28 15:45:47 err: this is an example error
$ curl -sSNT. localhost:8080 -u admin:admin | grep err:
01-28 15:45:45 err: this is an example error
01-28 15:45:46 err: this is an example error
01-28 15:45:47 err: this is an example error

Tips

  • craft commands using dashdash
  • create a bash-script to easily teleport into various apps:
#!/bin/bash
myapp(){  curl -sSNT. myapp.foo.com -u admin | stdbuf -i0 -o0 -e0 tr -d '\000'" }
appfoo(){ curl -sSNT. foo.com       -u admin | stdbuf -i0 -o0 -e0 tr -d '\000'" }

[[ ! -n "$1" ]] && { echo "apps: \n$(cat $0 | fgrep '(){' | head -n-1 | sed 's/(){.*//g' )" && exit; }

"$@"

Test development

$ npm install polka express
$ node test/express.js
$ node test/polka.js

Credits

  • @TooTallNate for pointing out the curl trick
  • @mk-pmb for pointing out the stdbuf trick