Dee*_*ons 81 windows console windows-vista node.js
作为node.js环境和哲学的全新,我想回答几个问题.我已经下载了用于Windows安装程序的node.js以及节点包管理器.Windows Cmd提示符当前用于运行nodejs应用程序.
cls清除命令窗口或命令提示符中的错误.node.js有等价物吗?console.clear不存在;(或以其他形式存在?
我通过以下代码创建了一个服务器
var http = require("http");
http.createServer(function (request, response) {
response.writeHead(200, {
"Content-Type": "text/html"
});
response.write("Hello World");
console.log("welcome world")response.end();
}).listen(9000, "127.0.0.1");
Run Code Online (Sandbox Code Playgroud)我将代码更改为下面并刷新浏览器以查找内容类型不会更改,如何查看更改?
var http = require("http");
http.createServer(function(request, response) {
response.writeHead(200, {"Content-Type": "text/plain"});
response.write("Hello World");
console.log("welcome world")
response.end();
}).listen(9000,"127.0.0.1");
Run Code Online (Sandbox Code Playgroud)
san*_*ppa 95
console.log('\033[2J');
Run Code Online (Sandbox Code Playgroud)
这适用于linux.关于窗户不确定.
您可以使用以下内容"欺骗"用户:
var lines = process.stdout.getWindowSize()[1];
for(var i = 0; i < lines; i++) {
console.log('\r\n');
}
Run Code Online (Sandbox Code Playgroud)
lfr*_*ree 68
process.stdout.write('\033c');
Run Code Online (Sandbox Code Playgroud)
这也适用于Windows.Win7至少.
lak*_*tak 53
这将清除Windows上的控制台并将光标置于0,0:
var util = require('util');
util.print("\u001b[2J\u001b[0;0H");
Run Code Online (Sandbox Code Playgroud)
process.stdout.write("\u001b[2J\u001b[0;0H");
Run Code Online (Sandbox Code Playgroud)
Nis*_*ant 44
这主要适用于Linux,但据报道也适用于Windows.
有Ctrl + L在Gnome终端在清零终端本身.它可以与Python,Node JS或任何使用终端的解释器一起使用.我倾向于多次清楚,因此这非常方便.你可以在Gnome Terminal做清楚Ctrl + L,它与REPL运行无关.
gui*_*web 27
并在Windows上以严格模式清除控制台:
'use strict';
process.stdout.write('\x1Bc');
Run Code Online (Sandbox Code Playgroud)
Ale*_*x K 11
从 Node.JS v8.3.0开始,您可以使用clear方法:
console.clear()
Run Code Online (Sandbox Code Playgroud)
没有在Windows上测试过这个,但是在unix上运行.诀窍在于child_process模块中.查看文档.您可以将此代码保存为文件,并在每次需要时将其加载到REPL.
var util = require('util');
var exec = require('child_process').exec;
function clear(){
exec('clear', function(error, stdout, stderr){
util.puts(stdout);
});
}
Run Code Online (Sandbox Code Playgroud)
使用官方的方式即可:
console.log('Blah blah blah'); // Prints "Blah blah blah"
console.clear(); // Clears, or in other words, resets the terminal.
console.log('You will only see this message. No more Blah blah blah...');Run Code Online (Sandbox Code Playgroud)