Is there a way configure node.js's repl? I want to require jquery and underscore automatically whenever the repl starts. Is there a file (noderc?) that node.js loads when it starts the repl?
The equivalent in Python is to edit ~/.ipython/ipy_user_conf.py
with:
import_mod('sys os datetime re itertools functools')
I don't know of any such configuration file, but if you want to have modules foo
and bar
be available in a REPL, you can create a file myrepl.js
containing:
var myrepl = require("repl").start();
["foo", "bar"].forEach(function(modName){
myrepl.context[modName] = require(modName);
});
and you when you execute it with node myrepl.js
you get a REPL with those modules available.
Armed with this knowledge you can put #!/path/to/node
at the top and make it executable directly, or you could modify your version of the repl.js module (source available at https://github.com/joyent/node/blob/master/lib/repl.js for inspection) or whatever :)