Marvin Caspar
Marvin Caspar

Reputation: 1409

Start NodeJs when starting Rails Server

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

Answers (2)

Marvin Caspar
Marvin Caspar

Reputation: 1409

OK, I found a solution. Put this line in an initializer:

system "node ./nodejs/nodejs-server.js &"

Upvotes: 1

TK-421
TK-421

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

Related Questions