本文介绍了Windows上的Node.Js-如何清除控制台的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

Being totally new into node.js environment and philosophy i would like answers to few questions. I had downloaded the node.js for windows installer and also node package manager.Windows Cmd prompt is being currently used for running nodejs apps.

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

  1. cls clears the command window or errors in command prompt. Is there a equivalent for node.js ? console.clear does not exist ;( or does it in some other form?

我通过下面的代码创建了服务器

I created a server through this code below

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

我将代码更改为以下代码,并刷新了浏览器,发现内容类型未更改,如何查看更改?

i changed the code to below and refreshed the browser to find that content type does not change, how do i get to see the changes?

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

推荐答案

console.log('\033[2J');

这在Linux上有效.不确定Windows.

This works on linux. Not sure about windows.

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

You can "trick" the user using something like this:

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

这篇关于Windows上的Node.Js-如何清除控制台的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-23 07:03