Last active
December 6, 2018 12:57
-
-
Save knbknb/0035cb8d3e2ce9214ac4004c6932b520 to your computer and use it in GitHub Desktop.
start node repl with favorite options and modules
This file contains hidden or 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
#!/bin/bash | |
# noder.sh : my node repl | |
# load nodejs repl with lodash preloaded | |
# - only for nvm users, | |
# - and lodash must be installed globally | |
# - optional: rlwrap utility installed with e.g. apt install rlwrap | |
# (if it is not installed remove rlwrap in NODE_PATH line below) | |
# knb 20181013 | |
node_version=$(node -p process.versions.node); | |
extra_path="$HOME/.nvm/versions/node/v$node_version/lib/node_modules/"; | |
script=$(cat <<END | |
let repl = require("repl"); | |
module.exports = repl; | |
let r = repl.start({ | |
ignoreUndefined: true, | |
replMode: repl.REPL_MODE_STRICT | |
}); | |
r.context.lodash = require("lodash"); | |
END | |
) | |
echo $node_version | |
NODE_PATH=$extra_path NODE_NO_READLINE=1 rlwrap node --use-strict -e "$script" | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment