node.js不是javascript框架或库,是基于Chrome V8引擎构建的运行时平台,是一个解析执行js的容器。
Node应用由模块组成,采用CommonJS模块规范。可以参考阮一峰编写的CommonJS规范。
node特性:
- event-driven(事件驱动)
- non-blocking(无阻塞IO模型)
node特点:
- lightweight(轻量,更好的移植性)
- efficient(高效的)
- 跨平台
第一个web服务器:helloworld
创建server.js文件
修改server.js文件如下
var http = require('http'); http.createServer(function (request, response) { response.writeHead(200, {'Content-Type': 'text/plain'}); response.end('Hello World\n'); }).listen(3000, '127.0.0.1'); console.log("Server running at http://127.0.0.1:3000/");
cmd下进入server.js所在目录
cmd下键入
node server.js
,开启服务5.浏览器下进入地址http://127.0.0.1:3000/
web服务器就搭好了。