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

Use Vue3+Vant component to implement App search history function (sample code)

I am currently developing a new app project. This...

Detailed explanation of keywords and reserved words in MySQL 5.7

Preface The keywords of MySQL and Oracle are not ...

Example code for implementing background transparency and opaque text with CSS3

Recently, I encountered a requirement to display ...

Javascript common higher-order functions details

Table of contents 1. Common higher-order function...

Specific operations of MYSQL scheduled clearing of backup data

1|0 Background Due to project requirements, each ...

HTML commonly used meta encyclopedia (recommended)

The Meta tag is an auxiliary tag in the head area...

How to implement parent-child component communication with Vue

Table of contents 1. Relationship between parent ...

Two ways to visualize ClickHouse data using Apache Superset

Apache Superset is a powerful BI tool that provid...

The difference and usage of distinct and row_number() over() in SQL

1 Introduction When we write SQL statements to op...

CSS easily implements fixed-ratio block-level containers

When designing H5 layout, you will usually encoun...

Detailed explanation of how to install PHP7 on Linux

How to install PHP7 on Linux? 1. Install dependen...

Vue+video.js implements video playlist

This article shares the specific code of vue+vide...