JavaScript Hot Swapper for Geddy
A small utility that tracks changes in JavaScript modules and reloads them automatically without the need to restart Geddy.
(This will also let you debug Geddy easily with WebStorm.)
Intended only for development. Do not use on production systems.
Note: Experimental. Use at your own risk.
Purpose
The purpose of this package is to minimize the need to restart Geddy while developing. The focus is in allowing small fixes to be made quickly, with the understanding that massive changes will still require restarting Geddy.
The package does not attempt to preserve any data between reloads. The principle here is the assumption that processing a HTTP request is a containable event with little effect on other HTTP requests. If that's not the case for your application, this package may not be good for you.
Setting Up
1. Install Packages
- Install Geddy locally using npm:
npm install geddy
- Install Geddy Hot Swapper locally using npm:
npm install geddy-hotswapper
2. Modify Geddy Just a Bit
Make a simple modification to your local copy of Geddy(!) to expose the application:
In this.start
function of node_modules/geddy/lib/geddy.js
, add the following
lines below app.init()
call.
if geddyconfigdebug === true geddyapp = app;
3. Prepare Launch Script
Instead of launching Geddy with geddy
, create a launch script which starts
Geddy and initializes Hot Swapper for Geddy. This file should be placed in the
root directory of your application.
Something along the lines of:
#!/usr/bin/env node var HotSwapper = ;var hotSwapper = ; // Ignore changes in node moduleshotSwapper; // Ignore changes in the launcher scripthotSwapper; // Start watching for changes in fileshotSwapperstart; // Start Geddyvar geddy = ; var geddyOpts = environment: processenvGEDDY_ENVIRONMENT || 'development'; geddystart geddyOpts ; // React to changes in files by reloading GeddyhotSwapper;
4. Done!
If you want to set up WebStorm, create a Node.js Run/Debug Configuration with the following settings.
Node interpreter | Point to node.exe |
Node parameters | Empty |
Working Directory | Your application's root directory |
JavaScript File | The launch file you just created |
Application Parameters | As you see fit |
Environment variables | As you see fit |
Compatibility
Tested on Windows, Node 0.10.22, and Geddy 0.11.8.
Troubleshooting
- Only works when Geddy configuration sets
debug = true
. - Only works when Geddy is running in single worker mode and does not use
geddy.startCluster()
.