创建第一个应用Nodejs应用


一、创建samp1.js

内容如下:

console.log("Hello World"); 

运行结果:

PS E:\study\nodejs\demo1> node .\samp1.js
Hello World

二、创建第一个应用

创建samp2.js

var http = require("http");

http.createServer(function(require, response){
    // 发送Http头部
    // HTTP状态值: 200: OK
    // 内容类型: text/plain
    response.writeHead(200,{'Content-Type': 'text/plain'});
    // 发送响应数据
    response.end("Hello World\n");
}).listen(8888);

console.log('server runing at http://127.0.0.1:8888/');

运行node .\samp2.js

访问 http://127.0.0.1:8888/

相关