新建一个hello.js

  1. /*
  2. 初识Node.js
  3. */
  4. console.log('hello node');

在cmd中输入 node hello.js
image.png

全局成员概述

1.1 包含文件名称的全路径

  1. console.log(__filename);

1.2 文件的路径(不包含文件名称)

  1. console.log(__dirname);

1.3 定时函数

  1. var timer = setTimeout(function(){
  2. console.log(123);
  3. },1000);

1.4 清除定时函数

  1. setTimeout(function(){
  2. // 清除定时函数
  3. clearTimeout(timer);
  4. },2000);

1.5 全局成员

在Node.js中没有window对象,但是有一个类似的对象global,访问全局成员的时候可以省略global

  1. global.console.log(123456);

1.6 注意

在 Node 中,采用 EcmaScript 进行编码。没有 BOM、DOM