Reputation: 1409
I have a Rails-App which includes a nodejs server. Is it possible to start and stop the nodejs server when I start/stop the rails server?
I want to put rails s
in my terminal and both server should start. By pressing ctrl + c both server should stop.
Upvotes: 1
Views: 1054
Reputation: 1409
OK, I found a solution. Put this line in an initializer:
system "node ./nodejs/nodejs-server.js &"
Upvotes: 1
Reputation: 10763
That sounds like a good candidate for a Rake task, something like (not tested):
# Rakefile
desc "Start Node and Rails servers"
task :start_servers do
`node myapp.js`
`rails s`
end
(And you can specify options as at the command line, for example to run on different ports, etc.)
Use rake start_servers
to run the task.
Upvotes: 1