Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to deploy egg applications on a self-built windows server (illustrated in detail)

2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/02 Report--

1. Log in to VPN using an IE browser

two。 Remote landing

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

4. Download source code > git clone * .git

5. Npm installation dependency > cd you-project > npm I

6. Start a single process using egg

/ / install the latest egg package / / create a new run.jsconst egg = require ('egg') in the project root directory; 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 TM egg.start ({ignoreWarning: true}) .then (app = > {app.listen (port)) App.logger.info (`server running on ${port}... `);})

Test start

> node run.js

7. Pm2 starts to 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: '4Grain, 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 boot

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 a startup script pm2_startup.bat

Echo offset 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 resurrectecho "Done"

Nssm.exe install MyPM2Service

Choose your own pm2_startup.bat path

Restart View

Summary

The above is the editor to introduce to you the self-built windows server how to deploy egg applications, I hope to help you, if you have any questions, please leave me a message, the editor will reply you in time. Thank you very much for your support to the website!

If you think this article is helpful to you, you are welcome to reprint it, please indicate the source, thank you!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report