-
-
Save adamsanderson/428142 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
## | |
# 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