1. Use IE browser to log in to VPN
2. Remote login
3. Install the latest node.js, git, etc. on the server
4. Download the source code
> git clone ****.git
5. npm install dependencies
> cd you-project
> npm i
6. Start using egg single process
// 安装最新的egg包
// 在项目根目录下新建run.js
const egg = require('egg');
function normalizePort(val) {
const listenPort = parseInt(val, 10);
if (isNaN(listenPort)) {
return val;
}
if (listenPort >= 0) {
return listenPort;
}
return false;
}
const port = normalizePort(process.env.PORT) || 3000;
egg.start({ ignoreWarning: true })
.then(app => {
app.listen(port);
app.logger.info(`server running on ${port} ...`);
});
Test start
> node run.js
7. pm2 start
- Install pm2
> npm i pm2 -g
- Create a new pm2 startup file
module.exports = {
apps : [{
name: '****',
script: 'run.js',
// Options reference: https://pm2.io/doc/en/runtime/reference/ecosystem-file/
args: 'one two',
instances: 4,
autorestart: true,
watch: false,
max_memory_restart: '4G',
env: {
NODE_ENV: 'development',
},
env_production: {
NODE_ENV: 'production',
APP_URL: '*****',
DB_HOST: 'localhost',
DB_PORT: '3306',
DB_USERNAME: '*****',
DB_PASSWORD: '*****',
DB_DATABASE: '*****',
EGG_SERVER_ENV: '****',
},
}],
};
- Production environment start
$ pm2 start ecosystem.config.js --env production
- Test environment start
$ pm2 start ecosystem.config.js
8. Open port 3000
Reference https://blog.csdn.net/zzq900503/article/details/11936379
9. Install mysql,
Reference: https://blog.csdn.net/u013235478/article/details/50623693, set mysql boot to start
10. Set pm2 to boot and use nssm
- View PM2_HOME, pm2 save
- Set the system environment variable PM2_HOME =
C:\Users\GYSD\.pm2
- Verify echo %PM2_HOME%
- Create the startup script pm2_startup.bat
@echo off
set HOMEDRIVE=C:
set PM2_HOME=C:\Users\***\.pm2
@REM Ensure that pm2 command is part of your PATH variable
@REM if you're not sure, add it here, as follow:
set path=C:\Users\****\AppData\Roaming\npm;%path%
@REM Optionally, you can add 'pm2 kill' just before
@REM resurrect (adding a sleep between 2 commands):
@REM pm2 kill
@REM timeout /t 5 /nobreak > NUL
@REM pm2 resurrect
@REM otherwise, you can simple call resurrect as follow:
pm2 resurrect
echo "Done"
nssm.exe install MyPM2Service
- Choose their own
pm2_startup.bat
path
- Choose their own
Restart view
Reference: https://blog.cloudboost.io/nodejs-pm2-startup-on-windows-db0906328d75