Skip to content

Instantly share code, notes, and snippets.

@uupaa
Created May 8, 2014 10:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save uupaa/7d02cdbe4cc3576a4abb to your computer and use it in GitHub Desktop.
Save uupaa/7d02cdbe4cc3576a4abb to your computer and use it in GitHub Desktop.
node repl mode, command line

node コマンドの引数

node コマンドの引数は $ node -h で見ることができます。

node -h

Usage: node [options] [ -e script | script.js ] [arguments]
       node debug script.js [arguments]

Options:
  -v, --version        print node's version
  -e, --eval script    evaluate script
  -p, --print          evaluate script and print result
  -i, --interactive    always enter the REPL even if stdin
                       does not appear to be a terminal
  --no-deprecation     silence deprecation warnings
  --trace-deprecation  show stack traces on deprecations
  --v8-options         print v8 command line options
  --max-stack-size=val set max v8 stack size (bytes)

Environment variables:
NODE_PATH              ':'-separated list of directories
                       prefixed to the module search path.
NODE_MODULE_CONTEXTS   Set to 1 to load modules in their own
                       global contexts.
NODE_DISABLE_COLORS    Set to 1 to disable colors in the REPL

REPL モード

$ node とタイプすると、REPL(Read-Eval-Print-Loop) モードになります。

REPL モードでは、対話型のコンソールを使いインタラクティブにスクリプトの評価と変数の確認などが行えます。

REPL モードで利用できるコマンドの一覧

.help とタイプすると、REPL モードで利用できる特別なコマンドの一覧が表示されます。

> .help
.break	Sometimes you get stuck, this gets you out
.clear	Alias for .break
.exit	Exit the repl
.help	Show repl options
.load	Load JS from a file into the REPL session
.save	Save all evaluated commands in this REPL session to a file

また _ には最後に評価した値が保存されています。

> [1,2,3]

> _
[1,2,3]

> _.length
3

> _+1
4
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment