I am running a script with node.js from the terminal (mac) and when I change my script I want to be able to rerun it without having to close and reopen terminal, Im a noob t
How are you starting Node? You should never have to close your terminal window. At the very least, you should be able to type ctrlC to stop it, then press the up arrow to bring the node command back from your command history, or type the command !!
, which means “the last command line I ran”, and hit the return key.
Or, use node-dev. It automatically restarts node when files change in the same directory as your node script. You can install it with npm. Then, run node-dev
instead of node
:
node-dev script.js
There are several modules for this that you can install using npm
, including:
This script is what I use. It works great!