1. Create the upload.server.js file in the root directory of the project and configure it as follows:
/* * @Description: gaobo * @Date: 2021-03-05 11:19:42 * @FilePath: \ upload server. * / / js/server configuration information const server = {host: '* * *. * * *. * * *. * * *', / / server IP port: '* * *, / / port general default 22 username: ", // username password: ", // password pathNmae: // scp2 const client = require('scp2'); // scp2 const client = require('scp2'); const ora = require('ora'); Const readline = require('readline-sync') const spinner = ora(' '); const Client = require('ssh2').Client; // Create shell script const conn = new Client(); server.username = readline.question('username:'); server.password = readline.question('password:',{hideEchoBack: true}); Console. log(' establishing connection '); Conn. on('ready', function () {console.log(' connected ') if(! For server pathNmae | | server pathNmae = = = '/') {the console. The log (' connection has been closed); conn.end() return false; } // Here I concatenate the location of the server resource directory, Conn. exec('rm -rf /home/' + server.pathNmae + '/*', function (err, stream) {console.log(' delete file '); Stream. on('close', function (code, signal) {console.log(' start uploading ') spinner.start(); client.scp(server.locaPath, { "host": server.host, "port": server.port, "username": server.username, "password": server.password, "path": '/home/' + server.pathNmae }, err => { spinner.stop(); if (! Err) {console.log(' project uploaded successfully '); } else {console.log("err", err)} conn.end()})})}).connect({host: server.host, port: Server. port, username: server.username, password: server.password //privateKey: "// use the privateKey to log in to the test server.Copy the code
  1. Execute the following command from Powershell
npm install scp2
npm install readlind-sync
npm install ssh2
node upload.server.js
Copy the code
  1. It is also possible to integrate upload functionality into scripts builds in package.json for one-click compilation package upload