node.js学习笔记

来源:互联网 发布:妆美堂shobi美瞳 知乎 编辑:程序博客网 时间:2024/06/06 16:42

转载自:http://www.runoob.com/nodejs/nodejs-http-server.html

下载安装node.js  

创建第一个应用:

1、在文件xxx下创建一个例如server.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/');

2、然后找到xxx文件,右键git

3、在$后面输入 node xxx.js,回车,得到Server running at http://127.0.0.1:8888/ ,

4、在浏览器中打开页面,输入http://localhost:8888 回车,页面中显示hello world

原创粉丝点击