Skip to content

Instantly share code, notes, and snippets.

@munro
Created January 11, 2012 18:43
Show Gist options
  • Save munro/1596121 to your computer and use it in GitHub Desktop.
Save munro/1596121 to your computer and use it in GitHub Desktop.
Auto Restart Node
// Auto restart server on file changes
(function () {
var fs = require('fs'),
original = require.extensions['.js'];
function exitOnChange(filename) {
fs.watchFile(filename, function (curr, prev) {
if (curr.mtime !== prev.mtime) {
process.exit();
}
});
}
require.extensions['.js'] = function (options) {
exitOnChange(options.filename);
original.apply(this, arguments);
};
exitOnChange(require.main.filename);
}());
@munro
Copy link
Author

munro commented Jan 11, 2012

while [ True ]; do npm start; done

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment