Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Javascript REPL from the command line

Whenever I am coding, I often find myself every now and then in a REPL to test out some concepts before I go ahead and implement it. For Ruby on Rails development I use PRYand for python I use bpython. Wondering whether there is an equivalent for that in javascript. Basically testing out javascript code from the terminal

like image 817
tawheed Avatar asked Jun 03 '13 20:06

tawheed


People also ask

Is there a REPL for JavaScript?

The REPL is an interactive environment that allows you to execute JavaScript code without first having to write it to a file. You can use the REPL to try out JavaScript code from other tutorials: How To Define Functions in JavaScript.

Can we use JavaScript in command line application?

Yes, you can run JavaScript in your terminal. Now, when you enter a command into your terminal, there are generally options, also called switches or flags, that you can use to modify how the command runs.


2 Answers

Even though I usually have a JavaScript-enabled browser open, I often find myself using the Node.js REPL.

Just run node in a command prompt, and it will open a REPL for you.

like image 95
Kendall Frey Avatar answered Oct 10 '22 19:10

Kendall Frey


You just need to use node.js :

$ node
> 1 + 1
> 2
> 

Although, this won't work for usual browser element (window, document) and DOM. If you want a browser environnement, checkout Phantomjs REPL and Casperjs - although I'm not sure about their capacity.

like image 40
Simon Boudrias Avatar answered Oct 10 '22 21:10

Simon Boudrias