Skip to content

Instantly share code, notes, and snippets.

@coolaj86
Last active January 8, 2017 17:23
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save coolaj86/4736427 to your computer and use it in GitHub Desktop.
Save coolaj86/4736427 to your computer and use it in GitHub Desktop.
REPL tools for NodeJS
#!/usr/bin/env node
/*jshint strict:true node:true es5:true
onevar:true laxcomma:true laxbreak:true eqeqeq:true immed:true latedef:true*/
(function () {
"use strict";
var repl = require("repl")
, context = repl.start("injs> ").context
, path = require('path')
, fs = require('fs')
, rcPath
, noderc
;
// http://stackoverflow.com/questions/9080085/node-js-find-home-directory-in-platform-agnostic-way
function getUserHome() {
return process.env[/^win/.test(process.platform) ? 'USERPROFILE' : 'HOME'];
}
rcPath = path.join(getUserHome(), '.noderc.js');
if (!fs.existsSync(rcPath)) { return; }
try {
noderc = require(rcPath);
Object.keys(noderc).forEach(function (key) {
context[key] = noderc[key];
});
} catch(e) {
console.error("failed to load '" + rcPath + "'");
}
}());
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment