新建一个hello.js
/*
初识Node.js
*/
console.log('hello node');
在cmd中输入 node hello.js
全局成员概述
1.1 包含文件名称的全路径
console.log(__filename);
1.2 文件的路径(不包含文件名称)
console.log(__dirname);
1.3 定时函数
var timer = setTimeout(function(){
console.log(123);
},1000);
1.4 清除定时函数
setTimeout(function(){
// 清除定时函数
clearTimeout(timer);
},2000);
1.5 全局成员
在Node.js中没有window对象,但是有一个类似的对象global,访问全局成员的时候可以省略global
global.console.log(123456);
1.6 注意
在 Node 中,采用 EcmaScript 进行编码。没有 BOM、DOM