A Mimosa module that will restart a node server when server code changes
JavaScript CoffeeScript
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Failed to load latest commit information.




This is a Mimosa module for restarting a node server when server-bound assets (like routes, general lib files) change.

For more information regarding Mimosa, see http://mimosajs.com

Note: Version 0.7.0 requires mimosa 0.13.3 or above.


Install 'mimosa-server-reload' using the mimosa mod:install mimosa-server-reload command. The mimosa-server module is a prereq.


The mimosa-server-reload module will point itself at a list of configurable files/folders and when the contents (recursive) of those change, it will work with both the mimosa-server and mimosa-live-reload modules to restart the user's server.

If you are using mimosa-server-reload, as part of restarting your server, this module shuts down the web socket connections that enable live reload so that the server can be closed. It restarts the server-side of the web socket connection, but does not reconnect with the client. So after the server is restarted, you need to refresh the browser to reconnect live reload.

Some prerequisites for this module are:

  • Must be installed inside Mimosa, where mimosa-server is located
  • You must be using mimosa-server
  • You must start Mimosa using the --server or -s flag
  • You must not being using Mimosa's hosted server. Your server.defaultServer.enabled value should be set to false.

mimosa-live-reload is not a prereq, but this module will work with that one if it is present to shut down socket connections.

Pre-restart Hook

As of version 2.2.14 of Mimosa and 0.9.0 of this module, if your server file (same location as startServer function) has a preMimosaRestart function that has been exported, mimosa-server-restart will call it before it restarts your server. This gives you an opportunity to clean up any resources like connections to databases, etc.

preMimosaRestart will be passed a callback. When everything that needs cleaning up is finished, execute the callback. This module will then execute the restart.

exports.preMimosaRestart = function (callback) {
  // Clean stuff up here

Default Config

  watch:["server.coffee", "server.js", "server.ls", "server.iced", "routes", "src", "lib"]
  • watch: an array of strings, folders and files whose contents will trigger a server restart when changed. By default all the possible server names generated by mimosa new are included as well as the routes folder, which is also delivered by mimosa new. Also considered defaults are typical source colde libraries: src and lib. Paths can be relative to the root of your project or absolute.
  • exclude: an array of strings and/or regexs, the list of files and file patterns to exclude from restarting the server. Can be a mix of regexes and strings. ex: ex: [/\.txt$/, "vendor/jqueryui.js"]. Can be left off or made null if not needed. Can be relative to the root of your project or absolute.
  • validate: a boolean, whether or not to validate changed files. When true, the default, mimosa-server-reload will require() the changed file. If the require fails, because it is invalid CoffeeScript/JavaScript for instance, Mimosa will not attempt to restart the server since the restart will likely fail. validate: true will cause problems if you point watch at non JavaScript files, for instance, server views. If you include your views folder in watch, you will want to turn validate off.