I think that the coffee-script module does not export REPL functionality that will be used programmatically, as the Node repl module does. But CoffeeScript has a repl.coffee file that you can use, although it is not exported in the main coffee-script module. Taking the command.coffee prompt (this is the file that was executed when the coffee command was run), we see that REPL only works with the repl file. So, running this script should launch CoffeeScript REPL:
require 'coffee-script/lib/coffee-script/repl'
This approach, however, is pretty hacky. The most important drawback is that it depends heavily on how the coffee-script module works internally and how it is organized. Nothing prevents you from moving the repl.coffee file from coffee-script/lib/coffee-script or changing the way it works.
A better approach would be to invoke the coffee command with no arguments, as on the command line, from Node:
{spawn} = require 'child_process' spawn 'coffee', [], stdio: 'inherit'
The stdio: 'inherit' causes the programmed command to read from stdin and write to stdout of the current process.
source share