Because CoffeeScript binary (coffee) use the following format:
Which does not specify fully qualified path on the shebang line, and will result in:
/usr/bin/env: node: No such fileordirectory
cm = require'coffee-module'
var cm = require('coffee-module');
Compile before publish the module
Compile after module install
alias node='env NODE_NO_READLINE=1 rlwrap -s 1000 -S "node> " node'
Persistent history file is saved in:
However, if by perserving the command history, Node REPL loses familiarity of color output and tab completion. This is a trade-off. To get around this problem, we can roll our own REPL or use an alternative. The best alternative I have found so far is also the one I am already using: CoffeeScript (see 1.6.3 change log). There is a history command built-in:
.break Sometimes you get stuck, this gets you out
.clear Break, and also clearthelocal context
.exit Exit the repl
.help Show repl options
.history Show commandhistory
.load Load JS fromafileintothe REPL session
.save Save all evaluated commands in this REPL session toafile
To share code between two different environment, first need to understand what are specific to browser and what are specific to Node. Shared code should be agnostic to both environments.
In browser environment, there is an obvious one: window object. In Node environment, there are a few objects that are not globally defined in browser: global, process, module, exports and more, see global objects. All these variables work, but exports is preferred.