
上QQ阅读APP看书,第一时间看更新
2.3 使用cmd命令运行Node.js程序
2.2节中直接在WebStorm中运行了Node.js程序,除了这种方法,还可以通过cmd命令运行Node.js程序。步骤如下。
(1)打开系统的“命令提示符”对话框,使用cd切换盘符命令进入Node.js程序的主文件index.js的根目录,如图2.12所示。

图2.12 在“命令提示符”对话框中进入Node.js程序的主文件index.js的根目录
(2)在“命令提示符”对话框中输入node ***.js命令,这里的Node.js程序主文件为index.js,因此输入node index.js命令,按Enter键,即可启动Node.js服务器,如图2.13所示。

图2.13 启动Node.js服务器
(3)打开浏览器,在地址栏中输入http://127.0.0.1:3000/,按Enter键,执行结果如图2.14所示。

图2.14 在浏览器中查看Node.js程序运行结果