Bash tip: starting a server and requesting it in one line

Written by Josh on July 20, 2014

Yesterday, my development cycle for working on the Flip the Classroom server involved writing a few lines of code, then performing this dance: ESC :w C-b up C-c C-l up enter C-b right up enter C-b down, and repeat. (That writes the current vim file, goes up a tmux pane, kills the process, clears the screen, restarts it by running the previous command, goes right a pane, reruns the previous command, and goes back down to vim.) I decided I needed to fix this, so I came up with this bash one-liner:

(sleep 0.5; ./script/send-request.js) | node ./bin/www

This uses a pipe to talk bash into starting the server while running the parenthesized code. The other branch waits half a second (waiting for the server to start up), then sends it the necessary request. (I’m working on logging at the moment.) This shows all of the output of ./bin/www. efficiency++ all day long!

(And yes, I just wrote two very short blog posts within ten minutes of each other.)

Copyright © 2014-2016 Joshua Oldenburg