任務時間:10min ~ 20minnode
Socket.IO 能夠實如今瀏覽器和服務器之間實時雙向通訊,本節課程將詳細介紹 Socket.IO 的搭建與部署,並在結束後完成 Socket.IO Web聊天室,幫助你們快速上手 Socket.IO。git
在 CentOS 環境中,能夠直接使用 yum 安裝 NodeJsgithub
yum install nodejs -y
任務時間:10min ~ 15minweb
yum install npm -y
任務時間:5min ~ 6minexpress
建立web環境目錄npm
mkdir www
cd www
初始化環境目錄(回車便可)json
npm init -y
關閉npm的https強制效驗瀏覽器
npm config set strict-ssl false
npm install express --save
任務時間:5min ~ 6min服務器
npm install --save socket.io
yum install git -y
git clone https://github.com/socketio/chat-example.git
mv chat-example/* /root/www/
{ "name": "socket-chat-example", "version": "0.0.1", "description": "my first socket.io app", "dependencies": { "express": "^4.15.2", "socket.io": "^1.7.3" }, "scripts": { "start": "node index.js" } }
npm install
node index.js
訪問 <您的 CVM IP 地址>:3000app