You can pipe into Node.js

1 min read

This post is part of my Today I learned series in which I share all my learnings regarding web development.

In July 2017 I wrote about ways to execute JavaScript snippets from your clipboard using process substitution. The snippet that I'm using since then to execute JavaScript snippets quickly is the following...

$ node <(pbpaste)

Today I came across a tweet by Julian Gruber and it turns out you use the pipe operator with the Node.js binary directly.

$ pbpaste | node

The result is the same but it looks nicer and feels better that using process substituion (<(...)). I have no idea how I missed this Node.js detail and checked the previous versions of Node.js and it works going down to Node.js v4 (that's what I have available on my machine). Good to know!

Load time