Is it possible to use node.js as a REPL wrapper?

This is a question about noob.

I am trying to use REPL (read-evaluate-print) node.jsas a shell JavaScriptfor working with JavaScript interactively. Unfortunately, I cannot define either variables or functions.

> var x = 'abc'
undefined
> function f () {}
undefined
>

What can I do to use node.jsREPL as a shell?

PS I know that I can use Rhino Shell , but I would prefer node.

+3
source share
1 answer

You can do it. However, these expressions have no return value, so node prints undefined.

> var x = 'abc'
undefined
> function f() {}
undefined
> f
[Function: f]
> x
'abc'
>
+8
source

All Articles