Node.js宣言:Node.js is a platform built on Chrome's JavaScript runtime for easily building fast, scalable network applications. Node.js uses an event-driven, non-blocking I/O model that makes it lightweight and efficient, perfect for data-intensive real-time applications that run across distributed devices. node
大概意思:Node.js是一个基于Chrome的JavaScript运行时的用户以轻松构建快速、可扩展的网络应用平台。 Node.js使用事件驱动、非阻塞I/ O模型,使它轻量级、高效和完美的适用于运行在分布式设备上的数据密集型的实时应用程序。 git
学习Node.js有2周了,本身也开发了一个开源的基于Bootstrap的应用OSN(https://github.com/obullxl/osnode-site),能轻松运行在免费百度云引擎上(http://obullxl.duapp.com/);如今总结一下,把学习过程当中的知识点总结一下。 github
6行代码1个JS文件轻松搭建HTTP服务器 express
var http = require('http'); var express = require('express'); var app = express(); app.use("/public", express.static(__dirname + '/public')); // 建立服务端 http.createServer(app).listen('80', function() { console.log('启动服务器完成'); });
使用方法: npm
一、把该数据内容复制到一个JS文件中,如“app.js”; 浏览器
二、把“app.js”文件放到须要做为服务器的目录下,文件发到“public”目录下; 服务器
三、运行命令“node app.js”,若没有安装express模块,运行命令“npm install express”进行安装; 网络
四、打开浏览器,访问服务器:http://127.0.0.1/public/文件名 app