Node.js是一個基於Chrome的JavaScript運行時的用戶以輕松構建快速、可擴展的網絡應用平台。 Node.js使用事件驅動、非阻塞I/ O模型,使它輕量級、高效和完美的適用於運行在分布式設備上的數據密集型的實時應用程序
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.js是一個基於Chrome的JavaScript運行時的用戶以輕松構建快速、可擴展的網絡應用平台。 Node.js使用事件驅動、非阻塞I/ O模型,使它輕量級、高效和完美的適用於運行在分布式設備上的數據密集型的實時應用程序。
學習Node.js有2周了,自己也開發了一個開源的基於Bootstrap的應用OSN(https://github.com/obullxl/osnode-site),能輕松運行在免費百度雲引擎上(http://obullxl.duapp.com/);現在總結一下,把學習過程中的知識點總結一下。
6行代碼1個JS文件輕松搭建HTTP服務器
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('啟動服務器完成');
});
使用方法:
1、把該數據內容復制到一個JS文件中,如“app.js”;
2、把“app.js”文件放到需要作為服務器的目錄下,文件發到“public”目錄下;
3、運行命令“node app.js”,若沒有安裝express模塊,運行命令“npm install express”進行安裝;
4、打開瀏覽器,訪問服務器:http://127.0.0.1/public/文件名
