3

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).

2
  • @Blender, you ought to post it as an answer, as it's a good alternative for my reply. Commented Dec 23, 2013 at 6:04
  • You can run it with Cscript.exe (see How to run .js file from a command line on windows?) but it is not really practical, also it even more limited that in the browser. Commented Dec 23, 2013 at 6:35

4 Answers 4

4

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".

Sign up to request clarification or add additional context in comments.

Comments

0

You can just use the developer tools.

For example, in Chrome, press F12. This will bring up the developer tools. The last option on the menubar is console. This will allow you to create JS variables and functions and to interact with DOM elements on the current page

2 Comments

I edited the question to emphasis why it has to be a windows console not just JS console in the browser.
@andrew.fox if you're working with files on the system, then you're going to need node.js (I haven't tried the Rhino JS Engine)
0

It's possible thanks to Mozilla Rhino JavaScript Engine.

To create a console window for JS:

1) Download Mozilla Rhino JavaScript Engine binary.

2) Extract: js.jar.

3) Create a script to run the console window (e.g. rihno_console.bat):

java -cp js.jar org.mozilla.javascript.tools.shell.Main

For more information about usage (for instance, and global functions inside this console) visit the Rhino Shell web page.

Comments

0

Just like I informed another user with the same question as yours who was faced with the same need, check out DeskJS (https://deskjs.wordpress.com). It's a portable Windows console application that lets you run pure JavaScript code and even load any existing JS files. It supports even the basic JS popup boxes implemented in browsers. You can save your commands as JS files that can be run on startup or by dragging-and-dropping them on the app. Plus there's so much more to it like you can create a build system for Sublime Text that can run JS files via cmd, it supports themes for customizing the entire console and snippets which let you save short snippets of JavaScript code for later use. Improvements are still being made on the app together with other native APIs being included. Hope this helps you as it did for me.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.