1

I'm programming with nodeJS. After I edit my code, I have to:

  1. Save the code in TextMate: cmd+s

  2. Shut down the server in bash: cmd+c

  3. Restart the server in bash: node myCode.js

  4. Refresh Google Chrome: cmd+r

Doing these steps over and over is quite repetitive. Is there a way to program my computer (mac OS X) to do all these steps in one go?

Randomblue
  • 3,445

2 Answers2

5

I don't know about the google chrome refresh but I use the 'node-dev' package via npm (npm install -g node-dev) and then run: node-dev app.js

It watches all of your files and restarts your node process each time the files change, eliminating steps 2+3.

Here's the Github link if you prefer not to use npm: https://github.com/fgnass/node-dev

(edit: Updated npm install command to include -g per HE's advice below)

  • I get the following error

    npm WARN prefer global node-dev@0.1.8 should be installed with -g

    – Randomblue Aug 06 '11 at 22:32
  • 1
    You should run npm install node-dev -g. This installs the package into the global node prefix, so that it is available anywhere on the system. – Jon Gauthier Aug 06 '11 at 22:33
2

Check out keyboard maestro for general UI automation and scripting. You may also want to look into the nodemon npm module which will restart your node.js server whenever a file changes. In practice, nodemon hasn't been a workable solution for me, though. It's similar to the node-dev package Brad suggested.

Peter Lyons
  • 1,862
  • 2
  • 12
  • 16
  • 1
    Why was nodemon not a workable solution for you? – Randomblue Aug 07 '11 at 06:32
  • None of these approaches AFAIK are intelligent about when to restart the app. So, for example, my system tests are running and I save a file, it will restart the app under my systems tests, sometimes leaving stale data in the DB. It's just a very blunt/dumb approach. It can be helpful but it's not a great solution. I've fallen back to setting up a Keyboard Maestro macro that manually kills and restarts the server when I want. – Peter Lyons Aug 07 '11 at 13:34