node.js - Create NodeJS standalone process -


i'm working on something, using nodejs, that's intended run service can connect with.

let's i'm working on calculator npm module.

i need run within repo following:

./node_modules/.bin/calculator start 

and want keep running forever, , can connect somehow (on port maybe?)

so, can send/receive messages calculator using node module, let's 'calculator-connector', example following:

var calcconnector = require('calculator-connector'),     calc = calcconnector.connect();  calc.add(1, 2); 

any idea how can achieve design?

i'd make this:

calculator shouldn't opinionated, , when run. i'd create in moment need it:

var calculator = require('calculator'); calculator.listen('localhost', 8000); // create service listening on port 8000 // create client capable of submitting tasks calcclient = createcalculatorclient('localhost', 8000)  calcclient.add(1,2) 

i believe such setup optimal quick development , debugging.

when you'll need things separated (say, calculator run on separate server), can simple node script which'll run calculator (basically, it's first 2 lines of snippet above) , create simple upstart job (in case of debianish server, or alternative on other platforms), that'll keep script alive.

ps: check out how express works, it's beautifully designed: http://expressjs.com/

read more upstart: http://upstart.ubuntu.com/getting-started.html


Comments

Popular posts from this blog

sublimetext3 - what keyboard shortcut is to comment/uncomment for this script tag in sublime -

java - No use of nillable="0" in SOAP Webservice -

ubuntu - Laravel 5.2 quickstart guide gives Not Found Error -