If using a foreign source, you can change to Ali source
Enter the yum repo
cd /etc/yum.repo.d
Change to Ali Yuan
wget http://mirrors.aliyun.com/repo/Centos-7.repo
Install nodeJS using EPEL
Verify that the system has installed the EPEL-Release package
yum info epel-release
Install epEL-Release, ignore it if you have it
yum install epel-release
Install nodejs
yum install nodejs
Viewing the Installed Version
node -v
Upgrade nodejs
NPM install -g n #n is the nodejs management tool
Install the latest version
n latest
Finally type n to switch versions
If the version switchover fails
vi ~/.bash_profile
Insert the following two lines at the end of the file
Export N_PREFIX=/usr/local # Node actual installation location export PATH=$N_PREFIX/bin:$PATHCopy the code
Run source ~/.bash_profile for the changes to take effect, and finally type n
Deploying front-end content
Install pm2 -g # install pm2
Ln -s /home/bin/pm2 /usr/local/bin/pm2
Write a Node startup script server.js
const fs = require('fs'); const path = require('path'); const express = require('express'); const app = express(); App. use(express. Static (path.resolve(__dirname, './manage'))) # res) { const html = fs.readFileSync(path.resolve(__dirname, './manage/index.html'), 'utF-8 ') res.send(HTML) #index.html}) app.listen(8002); ## Port for Web accessCopy the code
Then regenerate it into a package.json file
Type NPM init in the folder and press Enter
It can also be created using vi package.json
For package. Json content
{" name ":" back_manage ", "version" : "1.0.0", "description" : ""," main ":" server. Js ", # created before the name of the file "scripts" : {" test ": "echo \"Error: no test specified\" && exit 1" }, "author": "", "license": "ISC", "dependencies": { "express": "^ 4.15.3}}"Copy the code
Finally: Be sure to keep the Vue project package files, server.js startup scripts, and package.json configuration files in one folder. All three are equivalent files
Type NPM install into the folder to load some configuration files
Start server.js in the project folder
pm2 start server.js
Finally, use the browser to query the IP address: 8002
There are other pM2 commands
Pm2 show 0(id)// View details about a started application. Pm2 show list// View details about all started applications. Pm2 stop 0(id)// Stop an applicationCopy the code