Created
          December 3, 2010 10:21 
        
      - 
      
 - 
        
Save billywhizz/726797 to your computer and use it in GitHub Desktop.  
    example of hot code loading in a web server
  
        
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | var http = require('http'); | |
| var Script = process.binding('evals').Script; | |
| var httpd = new http.Server(); | |
| httpd.on("listening", function() { | |
| console.log('Server running at http://0.0.0.0:8124/'); | |
| }); | |
| var context = { | |
| "name": "billy" | |
| }; | |
| var sc = new Script("context.foo = function(req, res) {res.writeHead(200, {'Content-Type': 'text/plain'});res.end('Hello ' + context.name);}"); | |
| sc.runInNewContext({"context": context}); | |
| httpd.on("request", context.foo); | |
| httpd.listen(8124, "0.0.0.0"); | |
| setTimeout(function() { | |
| console.log("reload"); | |
| httpd.removeListener("request", context.foo); | |
| var sc = new Script("context.foo = function(req, res) {res.writeHead(200, {'Content-Type': 'text/plain'});res.end('Goodbye ' + context.name);}"); | |
| sc.runInNewContext({"context": context}); | |
| httpd.on("request", context.foo); | |
| }, 10000); | 
  
    Sign up for free
    to join this conversation on GitHub.
    Already have an account?
    Sign in to comment