Linux installation Node

Linux installation PM2

1. Project packaging

Packaging the Vue project with the NPM run build command generates the DIST production distribution package.Copy the code

2. Configure the startup file

In the dist production distribution package root directory, create the startup file index.js(file name can be customized)Copy the code
const express = require('express')
const compression = require("compression") / / gzip package
const fs = require('fs')

const app = express()
app.use(compression()) // Enable gzip code compression
app.use(express.static('/')) // Manage static resources
app.get('/ *'.function(req, res) { 
  const html = fs.readFileSync('./index.html'.'utf-8')
  res.send(html)
})

// Start the application with port 3000
app.listen(3000)
Copy the code

3. Install dependencies

1. Upload dist production release package to Linux server; 2. Go to the dist distribution package directory on the Linux server. 3. Run the following command to install the dependencies required in the index.js file: NPM install Express NPM install CompressionCopy the code

4. Start the project

pm2 start index.js
Copy the code