How to deploy egg applications on self-built Windows servers (with pictures and text)

How to deploy egg applications on self-built Windows servers (with pictures and text)

1. Log in to VPN using IE browser


2. Remote login

3. Install the latest node.js, git, etc. on the server

4. Download source code > git clone ****.git

5. npm install dependencies > cd you-project> npm i

6. Use egg single process startup

// Install the latest egg package // Create a new run.js in the project root directory
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 Startup

> node run.js

7. pm2 starts and installs 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 startup

$ pm2 start ecosystem.config.js --env production

Test environment startup

$ pm2 start ecosystem.config.js

8. Open port 3000

Reference https://www.jb51.net/article/172191.htm

9. Install mysql,

Reference: https://www.jb51.net/article/170594.htm

Set mysql to start at boot

10. Set pm2 to start at 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 a 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 simply call resurrect as follow:
pm2 resurrect
echo "Done"

nssm.exe install MyPM2Service

Choose your own pm2_startup.bat path

Restart to view

Summarize

The above is my introduction on how to deploy egg applications on self-built Windows servers. I hope it will be helpful to you. If you have any questions, please leave me a message and I will reply to you in time. I would also like to thank everyone for their support of the 123WORDPRESS.COM website!
If you find this article helpful, please feel free to reprint it and please indicate the source. Thank you!

You may also be interested in:
  • How to set up remote access to a server by specifying an IP address in Windows
  • How to set up remote desktop access by specifying an IP address on a Windows server
  • Windows Server 2008 R2 DNS Server Configuration Graphic Tutorial
  • Detailed explanation of how to install DNS server bind9 on Windows 7
  • How to Enable/Disable SMBv1, SMBv2, and SMBv3 in Windows Server
  • How to strengthen the security settings of Windows server operating system

<<:  In-depth understanding of MySQL master-slave replication thread state transition

>>:  Understand the initial use of redux in react in one article

Recommend

Move MySQL database to another disk under Windows

Preface Today I installed MySQL and found that th...

Rsync+crontab regular synchronization backup under centos7

Recently, I want to regularly back up important i...

Two examples of using icons in Vue3

Table of contents 1. Use SVG 2. Use fontAwesome 3...

Detailed explanation of Docker Secret management and use

1. What is Docker Secret 1. Scenario display We k...

Let's talk about parameters in MySQL

Preface: In some previous articles, we often see ...

Detailed tutorial on MySQL installation and configuration

Table of contents Installation-free version of My...

Getting Started: A brief introduction to HTML's basic tags and attributes

HTML is made up of tags and attributes, which are...

MySQL 5.7.23 installation and configuration graphic tutorial

This article records the detailed installation pr...

Pure CSS3 to achieve mouse over button animation Part 2

After the previous two chapters, do you have a ne...

CSS style does not work (the most complete solution summary in history)

When we write pages, we sometimes find that the C...