How do you pipe scripts into NodeJs from command line?

你说的曾经没有我的故事 提交于 2021-01-27 04:43:37

问题


From command line, I'd like to take a script from my paste board (FYI: pbpaste is an OSX feature) and pipe it into the Node's repl command line tool. For example:

pbpaste | node -e

This does not evaluate the contents in my clipboard. How do I get the runtime to do this?


回答1:


The -e option is for running JS passed as an argument. To run JS from stdin, you can simply pipe to node directly.

pbpaste | node



回答2:


This seems to do the trick:

node -e "$(pbpaste)"



来源:https://stackoverflow.com/questions/14352725/how-do-you-pipe-scripts-into-nodejs-from-command-line

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!