Skip to content

Instantly share code, notes, and snippets.

@adamsanderson
Forked from wesmaldonado/node_runner.rb
Created June 7, 2010 02:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save adamsanderson/428142 to your computer and use it in GitHub Desktop.
Save adamsanderson/428142 to your computer and use it in GitHub Desktop.
##
# Be lazy and restart your node.js app when you change things.
# Screenshot: http://img.skitch.com/20100606-mbi52g6knk3n83b6m3eqxr4pa4.png
# INSTALL:
# $ gem install watchr
# $ wget http://gist.github.com/raw/427720/2aae1f3b43a256f5ca07a603025d455aa92560e1/node_run
# $ cd YOUR_NODE_APP
# $ watchr node_runner.rb
#
# NOTES:
# @influx points out, you can do this with inotify tools also: http://wiki.github.com/rvoicilas/inotify-tools/
class NodeRunner
attr_accessor :pid
def initialize
@pid = nil
end
def start
@pid = fork do
exec "node app.js"
end
end
def restart
Process.kill "TERM", @pid
Process.wait @pid
start
end
end
@nr = NodeRunner.new
@nr.start
watch( '.*/*js' ) do |md|
puts "#{md[0].inspect} changed... restarting."
@nr.restart
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment