readline = require "readline"
rl = readline.createInterface
input: process.stdin
output: process.stdout
You could use named functions to better read callbacks instead of deeply nested anonymous functions:
Function for when a line is inputed
onLine = (line) ->
switch line.trim()
when "hello"
console.log "world"
Function for when the stream closes
onClose = -> # ...
rl
.on("line", onLine)
.on("close", onClose)
Here you could encapsulate the logic in a class:
class ReadlineLoop
constructor: ->
@rl = readline.createInterface
input: process.stdin
output: process.stdout
@rl.on("line", @onLine).on("close", @onClose)
onLine: => # ...
onClose: => # ...
And then to run it:
new ReadlineLoop()