n.
Node.js REPL with lodash and moment
Why?
Sometimes we use the Node.js REPL interface to experiment with code. Wouldn’t it be great to have that interface with some modules required by default?
Installation
$ npm install -g n.
NOTES
Do not forget the .
after n
!
Usage
$ n.n. >
attached modules
- loadash is now attached to the REPL context as
_
, so just use it:
n. > _.compact;[ 1, 2, 3 ]n. >
- moment is now attached to the REPL context as
m
, so just use it:
n. > m.format'1451783998074'n. >
Note:
The _
and m
characters is special in the Node REPL (see nodejs.org/api/repl.html).
n. redirects those special variables to $
per default, but you can set your own using the environment variable SPECIAL_VAR
like this:
$ SPECIAL_VAR=my_var n.n. > 123123n. > my_var123n. >
Also note that using the command .clear
you clear the context lodash is bound to.
Enjoy!
Acknowledgement
Most of code copied from n_.