日期:2014-05-16  浏览次数:20341 次

node.js简单的页面输出

安装过程就不说了。如果成功是能使用node的命令。node.js调试是非常方便的。每种后台语言都有一个向那个黑黢黢的控制台团输出语用的命令。node.js沿用FF那套东西,也就是console对象与其方法。我们首先建一个example.js文件,内容如下,然后在控制台打开它。

console.log("hello node.js")
for(var i in console){
    console.log(i+"  "+console[i])
}
node example.js。

你千万不要在node.js使用alert进行调试,那是浏览器带的全局方法,不报错才怪。

输出结果如下:

var log = function () {
  process.stdout.write(format.apply(this, arguments) + '\n');
}
var info = function () {
  process.stdout.write(format.apply(this, arguments) + '\n');
}
var warn = function () {
  writeError(format.apply(this, arguments) + '\n');
}
var error = function () {
  writeError(format.apply(this, arguments) + '\n');