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

commandlinefu

v0.0.6

Published

Easily use commandlinefu.com API with nodejs

Downloads

5

Readme

commandlinefu

Simple nodejs module to easily get commandlinefu.com snippets in JSON format.
https://nodei.co/npm/commandlinefu.png?downloads=true&downloadRank=true&stars=true code style: prettier Build Status

Install

npm install commandlinefu

Use

With nodejs:

// clfu.js
const clfu = require("commandlinefu");

clfu()
  .then((res) => console.log(res))
  .catch((e) => e);

node clfu.js output:

{
  "id": "5427",
  "command": "curl ifconfig.me",
  "summary": "Get your external IP address",
  "votes": "262",
  "url": "http://www.commandlinefu.com/commands/view/5427/get-your-external-ip-address"
}

This object will be referred as responseObject from now on.

Features

By default (no argument) it will returns a random responseObject.
You can pass a string as argument, in which case it will return an Array[] of responseObject{}.
Available arguments:

  • "popular" returns an Array of popular responseObject (which tbh doesn't change much over time)
  • "search:$var" returns an Array of responseObject related to $var

Example of dynamic search:

const userInput = "ssh"; // here you got user input as string

clfu(`search:${userInput}`)
  .then((res) => console.log(res))
  .catch((e) => e);
/* Outputs an array like : 
[
    {
        "id": "24887",
        "command": "ssh -L8888:localhost:80 -i nov15a.pem [email protected]",
        "summary": "port forwarding",
        "votes": "1",
        "url": "http://www.commandlinefu.com/commands/view/24887/port-forwarding"
    },
    {
        "id": "24879",
        "command": "rsync -e 'ssh -i /root/my.pem' -avz /mysql/db/data_summary.* ec2-1-2-4-9.compute-1.amazonaws.com:/mysql/test/",
        "summary": "rsync using pem file",
        "votes": "0",
        "url": "http://www.commandlinefu.com/commands/view/24879/rsync-using-pem-file"
    },
    {
        "id": "24863",
        "command": "cat myFile.json | ssh root@remoteSftpServer -o \"ProxyCommand=nc.openbsd -X connect -x proxyhost:proxyport %h %p\" 'cat > myFile.json'",
        "summary": "SFTP upload through HTTPS proxy",
        "votes": "0",
        "url": "http://www.commandlinefu.com/commands/view/24863/sftp-upload-through-https-proxy"
    }
]
*/

Discord bot

I originally wrote this for my discord bot. If you want to use this module for your own, feel free to check my (dirty) implementation :

  • here is where I take user input & call my module to fetch stuff accordingly
  • here are my format functions. Note that I divide the response into several chunks to get around Discord limitations (maximum 2000 characters for a message).

CLI

Nodejs make it easy to wrap functions into a custom CLI suiting your needs. In terminal :

mkdir myCli
cd ./myCli
npm init # you can spam 'return' key for now
npm i commandlinefu # grab this module
touch index.js

This is the content of your index.js :

const clfu = require("commandlinefu");

const commandlinefu = async () => {
  if (!process.argv.slice(2)[0]) {
    return await clfu()
    .then(res => console.log(res.command))
    .catch(e => console.error(e));
  }
  else if (process.argv.slice(2)[0]) {
    return await clfu(process.argv.slice(2)[0])
      .then(res => console.log(res))
      .catch(e => console.error(e));
};

commandlinefu();

That's it! Now back into your terminal:

node index.js # calling clfu without argument
ps auxw | awk '/(apache|httpd)/{print"strace -F -p " $2}' | sh # this is 'res.command' printed in stdout
node index.js search:ssh # calling clfu with "search:ssh" argument, we get an array like we're supposed to :
[
  {
    id: '24887',
    command: 'ssh -L8888:localhost:80 -i nov15a.pem [email protected]',
    summary: 'port forwarding',
    votes: '1',
    url: 'http://www.commandlinefu.com/commands/view/24887/port-forwarding'
  },
  {
    id: '24879',
    command: "rsync -e 'ssh -i /root/my.pem' -avz /mysql/db/data_summary.* ec2-1-2-4-9.compute-1.amazonaws.com:/mysql/test/",
    summary: 'rsync using pem file',
    votes: '0',
    url: 'http://www.commandlinefu.com/commands/view/24879/rsync-using-pem-file'
  },
  {...more objects}
]

This is the basic principle. You can parse & do your stuff with those arrays in the else if block of aforementioned index.js file.
If you never used process.argv before, this read should get you started

More

If you're looking for out-of-the-box CLI instead of a reusable function, it may be worth checking this repo.
At least it helped me decipher commandlinefu.com API endpoints, so thank you nire0510 :)

Todo