XNPM

Use sparkfun to track how and when I use npm


An experiment to use sparkfun to record how and when I use the npm command.

Code


# the xnpm function
function xnpm () {
# run npm command as usual
npm $@
 # encode url to escape spaces
command=”npm%20"`echo $@ | sed ‘s/ /%20/g’`
 # send request to sparkfun
curl -s -o /dev/null “https://data.sparkfun.com/input/PUBLIC_KEY?private_key=PRIVATE_KEY&command=$command" 2>&1
}
# alias npm to xnpm
alias npm=’xnpm’

Replace the PRIVATE_KEY and PUBLIC_KEY with your own.

The command params is the field you need to set when create a new Data Stream. Here I only need to care which command I was running. Sparkfun will add the timestamp by default.

Result


Here’s what I got from Sparkfun.

Email me when xvfeng publishes or recommends stories