1.找一个目录手动创建js文件,内容如下:

var http = require('http');
http.createServer(function (request, response) {
    // 发送 HTTP 头部 
    // HTTP 状态值: 200 : OK
    // 内容类型: text/plain
    response.writeHead(200, {'Content-Type': 'text/plain'});
    // 发送响应数据 "Hello World"
    response.end('Hello World\n');
}).listen(8888);
// 终端打印如下信息
console.log('Server running at http://127.0.0.1:8888/');

node学习二之运行node程序

2.命令行到该文件目录下,执行该文件

cd C:\Users\tianyong\Desktop\node

3.执行ty.js文件

node ty.js

node学习二之运行node程序

4.访问http://127.0.0.1:6666/

node学习二之运行node程序

相关文章: