上一次已經配置好靜態網頁
接下來部署一個簡單的node服務
有多簡單?就一個app.js 哈哈
- 在服務器安裝node
在這裏找到自己想安裝的版本 https://nodejs.org/dist/
我選的是這個 https://nodejs.org/dist/v12.13.0/node-v12.13.0-linux-x64.tar.xz 公司裏面現在也用這個版本
然後運行
mkdir /opt/soft/node 我的node存放目錄
cd /opt/soft/node 打開
wget https://nodejs.org/dist/v12.13.0/node-v12.13.0-linux-x64.tar.xz 下載node
tar -xvf node-v12.13.0-linux-x64.tar.xz 下載好後解壓
cd node-v12.13.0-linux-x64/bin 打開可執行文件目錄
./node -v 查看當前node版本
vi /etc/profile 配置全局node
添加下面兩條信息
export NODE_PATH=/opt/soft/node/node-v12.13.0-linux-x64/bin
export PATH=${PATH}:${NODE_PATH}
. /etc/profile 讓配置生效
運行node -v 查看是否成功
tips :可以裝一個nvm 更方便包的管理
- app.js準備
const http = require('http')
http.createServer(function(req,res){
console.log(req.httpVersion);
console.log(req.headers);
console.log(req.method);
console.log(req.url);
console.log(req.trailers);
console.log(req.complete);
res.writeHead(200,{'Content-Type':'text/html'});
res.write("hello my first node server !")
}).listen(5000)
console.log('server start in 5000');
- 上傳至雲服務並運行 app.js
成功運行node服務 接下來把node服務框架搭建起來 暫時準備用koa2 加油!!!