New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

geddy-hotswapper

Package Overview
Dependencies
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

geddy-hotswapper

Track changes in JavaScript files and reload them automatically without need to restart Geddy

  • 0.0.1
  • latest
  • npm
  • Socket score

Version published
Weekly downloads
1
decreased by-85.71%
Maintainers
1
Weekly downloads
 
Created
Source

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

  1. Install Geddy locally using npm: npm install geddy
  2. 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( geddy.config.debug === true ) {
  geddy.app = app;
}

View example

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	= require( 'geddy-hotswapper' );
var hotSwapper	= new HotSwapper();

// Ignore changes in node modules
hotSwapper.exclude( new RegExp( 'node_modules' ) );

// Ignore changes in the launcher script
hotSwapper.exclude( new RegExp( 'app-debug.js' ) );

// Start watching for changes in files
hotSwapper.start();


// Start Geddy
var geddy = require('geddy');

var geddyOpts = {
	environment: process.env.GEDDY_ENVIRONMENT || 'development'
};

geddy.start( geddyOpts );


// React to changes in files by reloading Geddy
hotSwapper.on( 'swapped',
		function( filename )
		{
			var config = require( 'geddy/lib/config' );

			geddy.config = config.readConfig( geddyOpts );
			geddy.worker.config = geddy.config;

			hotSwapper.clear( require.resolve( './config/router' ) );

			var geddyInit = require( 'geddy/lib/init' );
			geddyInit.init( geddy.app, function() { console.log( 'Matrix reloaded' ); } );
		}
	);

4. Done!

If you want to set up WebStorm, create a Node.js Run/Debug Configuration with the following settings.

Node interpreterPoint to node.exe
Node parametersEmpty
Working DirectoryYour application's root directory
JavaScript FileThe launch file you just created
Application ParametersAs you see fit
Environment variablesAs 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().

Keywords

FAQs

Package last updated on 13 Dec 2013

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc