如何运行JavaScript的Windows控制台 [英] How run a windows console for JavaScript
问题描述
我想在Windows 7上有一个控制台窗口(命令行),这将允许我像使用python控制台一样使用JavaScript。
更新:
从控制台(或通过它运行的脚本)访问文件很重要。
您可以使用 Node.js 的REPL。为此,请按照以下步骤操作:
- 下载并安装Node.js 。
- 从开始菜单/开始屏幕或直接
node.exe调用Node.js
安装路径(例如C:\Program Files\\\
)。
odejs\\\
ode.exe - li>
您可能希望将安装路径添加到PATH环境变量中以方便使用。
注意:要离开node.js,请按 Ctrl + C
两次。
< hr>
要访问本地文件,您需要文件系统模块。这是一个使用示例:
var fs = require(fs);
fs.readFile(
C:\\test.txt,
function(err,data)
{
if(!err)
console.log(data.toString());
}
);
这将输出文件的内容 C:\test.txt
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).
You can use Node.js's REPL. To do so follow this steps:
- Download and Install Node.js.
- Call Node.js from the Start Menu / Start Screen or directly
node.exe
installation path (e.gC:\Program Files\nodejs\node.exe
). - 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".
这篇关于如何运行JavaScript的Windows控制台的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!