阿里云服務(wù)器搭建node.js環(huán)境

1.進(jìn)入服務(wù)器,跟新服務(wù)器各種插件

sudo apt-get update

2.安裝響應(yīng)必要的組件

sudo apt-get install vim openssl build-essential libssl-dev wget git

3.服務(wù)器安裝nvm
在git中搜索nvm,然后找到 curl 或者 wget 如下:

curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.35.2/install.sh | bash

或者

wget -qO- https://raw.githubusercontent.com/nvm-sh/nvm/v0.35.2/install.sh | bash

4.安裝好了之后 新打開一個新的命領(lǐng)行控制器,去node官網(wǎng)查看當(dāng)前node最新版,版本號 然后安裝nodejs

nvm install <node.js最新穩(wěn)定版版本號>

5.指定當(dāng)前服務(wù)器使用的node版本號

nvm use <nodejs版本號>
nvm alias default <nodejs版本號> 

指定好了之后,能查看當(dāng)前nodejs版本號

node -v

6.安裝npm:

npm --registry=https://registry.npm.tobao.org install -g npm

7.執(zhí)行命令提升系統(tǒng)文件載入速度

echo fs.inotify.max_user_watches=524288 | sudo tee -a /etc/sysctl.conf && sudo sysctl -p

8.安裝cnpm:

npm --registry=https://registry.npm.tobao.org install -g cnpm

9.安裝node環(huán)境常用的工具包

npm  i pm2 webpack gulp grunt-cli -g

10.環(huán)境安裝完畢,測試下,創(chuàng)建一個文件app.js

vi app.js

文件寫入代碼

const http = require('http')

http.createServer(function(req, res){
    res.writeHead(200,{'Content-Type':'text/plain'})
    res.end('結(jié)束')
}).listen(8001)

console.log('開啟服務(wù)')

11.可以使用 pm2來運(yùn)行項(xiàng)目

pm2 start app.js
// 查看logs
pm2 logs

12.搭建Nagix

// 先關(guān)閉服務(wù) (如果沒有可以略過)
sudo service apache2 stop
// 刪除apache
update-rc.d -f apache2 remove
sudo apt-get remove apache2
// 跟新
sudo apt-get update
// 安裝nagix
sudo apt-get install nginx
// 進(jìn)入nginx文件夾
cd /etc/nginx/
// 進(jìn)入文件夾 con f.d
// cd conf.d
最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容