1

I'm using NodeJS to do two things:

  1. Start a server and listen on a port
  2. Run a grunt task

The calls are as follows:

node livereload.js
grunt watch

But the problem is that the first call doesn't allow subsequent tasks to be run! So I have to do CTRL+C in the cmd to run another command.

Even doing:

node livereload.js & grunt watch

Doesn't work! Do I have to do something in the livereload.js file to make it exit the command so I can call another one?

The file looks like:

var lrserver = require('tiny-lr')();
lrserver.listen(35729, function(err) { console.log('LR Server Started'); });

I've even tried:

node livereload
.exit
grunt watch

But that doesn't work either.

Update: It seems that the grunt watch command is in fact being run with my first code example, but because it doesn't get exited it doesn't show the console logs from grunt because it's still on the livereload one. Any ideas what the best way to fix this is then?

What's the correct way to do CTRL+C but from NodeJS? It would seem I need to do this after the console.log

6
  • Which OS are you using? Commented Mar 9, 2015 at 16:47
  • You give node a script to listen to a port indefinitely, and question why it doesn't stop listening without Ctrl+C? Well, why should it stop listening if you tell it to listen? Downvoted for question having no logical base. Also next time include the code you run, accidentally found it here: github.com/mklabs/tiny-lr/issues/73 Commented Mar 9, 2015 at 17:20
  • @alandarev feel better now? Commented Mar 9, 2015 at 17:20
  • No. I feel sorry for the answer authors as they tried to answer meaningless question. Commented Mar 9, 2015 at 17:22
  • @alandarev Then go outside then if this question is meaningless to you. Because it's relevant to me! Commented Mar 9, 2015 at 17:23

2 Answers 2

2

I think this is what you are after:

node livereload.js && grunt watch

Sign up to request clarification or add additional context in comments.

2 Comments

The command runs as I've discovered. But I don't see the console logs from the grunt watch command as cmd is still on the previous command.
Ok sorry, I didn't realise you were operating in Windows - see Lee Daniel Crocker's answer above.
1

In Windows, try:

start /B node livereload.js

That's roughly the equivalent of Linux's

node livereload.js &

5 Comments

Still get the flashing _ after the command unless I do CTRL+C
I don't know what your code is doing. Maybe it specifically listens for keyboard input, so it's not designed to be backgrounded?
I would assume process.exit(), but I'm sure that's not what you want.
Ah yeah that just closes the cmd prompt so it's not the same. I'm asking the guys who created the livereload module to find out why it's not exiting without CTRL+C here: github.com/mklabs/tiny-lr/issues/73
So it seems like START /B is the best way to handle this according to the guys who developed the module. Thanks for the help.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.