Hey! I'm available for hire (and I appreciate tips)  



There's an open issue for adding .noderc.js support to node's repl, but the patch hasn't been pulled in at the time of this writing.

A REPL of my own

In the meantime, I read a bit in Axel Rauschmayer's post on Executing code at the REPL's startup, as well as the aforementioned bug patch and came up with a REPL of my own.

I called it injs for interactive nodejs, after the style of ruby's irb.

You can install like so:

curl -L -s https://gist.github.com/raw/4736427/injs.js > /tmp/injs.js
chmod a+x /tmp/injs.js
sudo mv /tmp/injs.js /usr/local/bin/injs

injs

And from the new REPL try

injs> 0.1 + 0.2
0.30000000000000004
injs> .exit

You can inspect the source at https://gist.github.com/coolaj86/4736427

Adding clear

For convenience I like to have a clear(); method that does the equivalent of bash's clear and cmd.exe's cls.

Just put this snippet in ~/.noderc.js:

(function () {
  "use strict";
  
  exports.clear = function () {
    process.stdout.write('\u001B[2J\u001B[0;0f');
  };
}());

Everything attached to exports will be reattached to the REPL's global context. You can call any such method like so:

injs> clear();

Tada!


By AJ ONeal

Was this useful to you? Share it!

Also, you can give me a tip or hire me.


Published

2013-2-7

Categories


Tags