Node 官方提供了 repl 模块,实现一个交互式解析器,它可以作为一个独立程序使用或者嵌入到其它应用中:
node 命令使用
如果你已经安装了 node,那么你可以在命令行直接输入 node 命令便可以进入一个交互式 javascript 命令行界面,这里你可以敲一些 javascript 表达式,甚至你都可以把它当成计算器使用:
$ node
> new Date()
2018-12-06T03:30:46.242Z
> 3 + 5
8
>
在交互式命令行中当你输入 .help 命令,你会发现它提供了几个简单且方便的交互命令:
> .help
.break Sometimes you get stuck, this gets you out
.clear Alias for .break
.editor Enter editor mode
.exit Exit the repl
.help Print this help message
.load Load JS from a