Last active
January 8, 2017 17:23
-
-
Save coolaj86/4736427 to your computer and use it in GitHub Desktop.
REPL tools for NodeJS
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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