Windows 上的 Node.Js - 如何清除控制台

新手上路,请多包涵

作为对 node.js 环境和哲学的全新了解,我想回答几个问题。我已经下载了用于 Windows 安装程序的 node.js 以及节点包管理器。Windows Cmd 提示符当前正在用于运行 nodejs 应用程序。

  1. cls 清除命令窗口或命令提示符中的错误。 node.js 是否有等价物? console.clear 不存在 ;( 还是以其他形式存在?

  2. 我通过下面的代码创建了一个服务器

   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");

我将代码更改为下面并刷新浏览器以发现内容类型没有更改,我如何才能看到更改?

 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");

原文由 Deeptechtons 发布,翻译遵循 CC BY-SA 4.0 许可协议

阅读 917
2 个回答
console.log('\033[2J');

这适用于linux。不确定窗户。

您可以使用以下方式“欺骗”用户:

 var lines = process.stdout.getWindowSize()[1];
for(var i = 0; i < lines; i++) {
    console.log('\r\n');
}

原文由 sanatgersappa 发布,翻译遵循 CC BY-SA 3.0 许可协议

只需使用官方方式:

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

原文由 bbkrz 发布,翻译遵循 CC BY-SA 4.0 许可协议

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题