forever has a -w --watch flags as well as --watchDir, havent use them yet. i use nodemon for development and forever or https://github.com/visionmedia/mon in production
Am Samstag, 12. Januar 2013 20:41:40 UTC+1 schrieb nin jin: > > Problems: > 1) When some files changed, needs to restart for applying that. > 2) When application downed, needs to start it again > > I found some external utils: > > a) nodemon > https://github.com/remy/nodemon > Transparent node-replacer. This is really cool util for (1) but not for (2) > > b) supervisor > https://github.com/isaacs/node-supervisor > Node-replacer, but do not transmit cmd arguments to node. This is > important for me because i need --harmony flag. > > c) forever > https://github.com/nodejitsu/forever > Solving (2) problem, but not (1) > > d) some modules for hot-swapping, but without native api, it is dangerous. > > Of course, i can use nodemon+forever, but this is overkill. Daemon that > monitoring daemon that monitoring application.. > > And i invent new one :) > > $.jin.persistent - node module that integrates in your application, and > keeps it up and up-to-date. Let us write something simple: > > ================================================ > require( 'jin' ).persistent( function( $ ){ > // $ is autoloader but you are not required to use it > > console.log( '2 * 2 = ' + 2 * 2 ) > > if( Math.random() < 0.3 ) throw new Error( 'Something wrong!' ) > } ) > ================================================ > > In console you see something like that while you editing the source: > > ================================================ > >node --harmony . > $.jin.persistent: Starting application... > 2 * 2 = 4 > $.jin.persistent: Some files changed! > $.jin.persistent: Starting application... > 2 * 2 = 4 > $.jin.persistent: Some files changed! > $.jin.persistent: Starting application... > 2 * 2 = 4 > Error: Something Wrong! > at \index.js:5:37 > at module.exports.$.jin.proxy.apply.proc > (\node_modules\jin\sync2async.js:19:18) > $.jin.persistent: Application halted (1) > $.jin.persistent: Some files changed! > $.jin.persistent: Starting application... > 2 * 2 = 4 > ================================================ > > Note, application did not restart after this error, because it fails on > statup and strongly needs for changes for starting again. Autorestart > enables after 1s timeout. > Let us write some server. Let it be service that gets domain list and > returns json with its ip's as integers. > > ================================================ > require( 'jin' ).persistent( function( $ ){ > > $.express() > .use( $.jin.sync2middle( function( req, res ){ > > var domains= req.url.replace( /^\/+|\/+$/g, '' ).split( '/' ).map( > decodeURIComponent ) > > var ips= domains.map( function( domain ){ > return $.dns.lookupSync( domain ) > } ) > > var map= {} > domains.forEach( function( domain, index ){ > try{ > numbers= String( ips[ index ] ).split( '.' ).map( Number ) > map[ domain ]= numbers[ 0 ] * 256 * 256 * 256 > + numbers[ 1 ] * 256 * 256 > + numbers[ 2 ] * 256 > + numbers[ 3 ] > } catch( error ){ > map[ domain ]= error > } > } ) > > return map > > } ) ) > .listen( 80 ) > > } ) > ================================================ > > This is implementation of map-reduce pattern. First,simultaneously send > requests to dns. Second, gets responses in right sequence, and handle all > errors occurring during that. > > I run that application by: > > npm install jin > node --harmony dns-er.js > > While i write this source, server has automatic restarts. And sometimes > server downs with any error. But when i fix bugs it ups automatically. > All i do after editing is refreshing this page: > > http://localhost/google.com/undefined.host/yandex.com/%D0%BF%D1%80%D0%B5%D0%B7%D0%B8%D0%B4%D0%B5%D0%BD%D1%82.%D1%80%D1%84/ > and getting that in browser: > > ================================================ > { > > - google.com: 1249765070, > - undefined.host: > { > - code: "ENOTFOUND", > - errno: "ENOTFOUND", > - syscall: "getaddrinfo" > }, > - yandex.com: 1680561923, > - президент.рф: 3285194843 > > } > ================================================ > > $.jin.persistent uses fs-watch-tree and you can setup this watcher by > optional second argument that passes as is. By default watched all files > and directories that starts with english letter. > See more about this config: > https://github.com/busterjs/fs-watch-tree#watchtreedir-options-callback > > And more about jin library: https://github.com/nin-jin/node-jin > -- Job Board: http://jobs.nodejs.org/ Posting guidelines: https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines You received this message because you are subscribed to the Google Groups "nodejs" group. To post to this group, send email to nodejs@googlegroups.com To unsubscribe from this group, send email to nodejs+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/nodejs?hl=en?hl=en