Skip to content

Commit

Permalink
new file: both_example.js
Browse files Browse the repository at this point in the history
  • Loading branch information
shimondoodkin committed Aug 10, 2010
1 parent bf16e9b commit 975890d
Showing 1 changed file with 53 additions and 0 deletions.
53 changes: 53 additions & 0 deletions both_example.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@

////////example:
require.paths.unshift(__dirname); //make local paths accessible

var autoreload= require('./autoreload');
var mymodule= require('./mymodule');
autoreload.watchrel('mymodule.js', function (newmodule){
mymodule=newmodule;
/* also you can put hre staff to make you module looklike it was initialized well. */
});
//autoreload.watch(mymodule.filename, function (newmodule){ mymodule=newmodule; }); // might not work if when started the module has errors or filename export is missing


var sys = require('sys'),
http = require('http');
http.createServer(function (req, res) {

try
{

res.writeHead(200, {'Content-Type': 'text/plain'});
response.end(mymodule.time() + '\n');
res.end();

}
catch(e)
{
sys.puts(e.stack);
}

}).listen(8124);
sys.puts((new Date).toTimeString()+' Server running at http://127.0.0.1:8124/');


// exit if any js file or template file is changed.
// it is ok because this script encapsualated in a batch while(true);
// so it runs again after it exits.


var autoexit_watch=require('autoexit').watch;
var on_autoexit=function () { // if this function return true it means to ignore the exit;

}
autoexit_watch(__dirname,".js", on_autoexit);
//autoexit_watch(__dirname+"/templates",".html", on_autoexit);




//////////end example
// notice the try-catch witch makes your applicaiton not crush on errors


0 comments on commit 975890d

Please sign in to comment.