Archive
Posts Tagged ‘one-liner’
[nodejs] Node.js one-liner
November 23, 2015
Leave a comment
Problem
You want to execute a Node.js snippet in the command-line non-interactively. Why? Maybe you want to include it in a Bash script.
Solution
$ node -p '"jabba".split("").reverse().join("")'
abbaj
The option “-p” means “print result of --eval“.
Same thing in Python
$ python2 -c "print 'abc'.upper()"
ABC
# or, it can be multiple lines too
$ python2 -c "
for x in range(5):
print x
print 'Finished'
"
The option “-c” means “command”.
Python web server on localhost
November 10, 2011
Leave a comment
python2 -m SimpleHTTPServer
Tip from here.
Python 3
python3 -m http.server
Update (20170914)
If you want to share a file with several people, use Node.js. The Python web server (as seen above) is single threaded, while Node.js works in async mode. Read more here.
Categories: python
localhost, one-liner, web server
