Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How run a windows console for JavaScript

I would like to have a console window (a command line) on Windows 7 which will allow me to play with JavaScript just like a python console.

Update: It's important to have a file access from within the console (or script run through it).

like image 230
andrew.fox Avatar asked Feb 26 '26 03:02

andrew.fox


1 Answers

You can use Node.js's REPL. To do so follow this steps:

  1. Download and Install Node.js.
  2. Call Node.js from the Start Menu / Start Screen or directly node.exe installation path (e.g C:\Program Files\nodejs\node.exe).
  3. Enjoy!

You may want to add the installation path to your PATH enviroment variable for ease of use.

Note: to leave node.js press Ctrl + C twice.


To access the local files, you will need the File System module. This is an example of usage:

var fs = require("fs");
fs.readFile(
    "C:\\test.txt",
    function(err, data)
    {
        if (!err)
        console.log(data.toString());
    }
);

This will output the contents of the file C:\test.txt to the console.

Note: An unhandled exception will cause node.js to "crash".

like image 162
Theraot Avatar answered Feb 28 '26 02:02

Theraot



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!