Deploying a nodejs app to Production
Deploy on server using pm2, set up nginx reverse proxy https://www.freecodecamp.org/news/deploy-nodejs-app-server-to-production/ requirements: server with ssh and root access
- create project directory
- create app.js file with following content
- run
npm install
- configure nginx (skip for now) reverse proxy
- run app as process using pm2
Deploy on server using systemd, but not manual update / revision control system (git) https://medium.com/swlh/localhost-to-com-deploying-a-web-app-for-beginners-ea05b0213eb7 requiremenst: working local project, server with ssh and root access
- install software on ser, such as nodejs
- run on server boot using
stemd service manager in ubuntu, write to
sudo vim /etc/systemd/system/nodeapp.service
[Unit]
Description=NodeToProdution
After=multi-user.target # Run once the multi user environment has loaded.
[Service]
Type=idle # Run only after everything else is loaded
Environment="PORT=8080" # This is optional, for environment variables.
ExecStart=/usr/bin/node /root/myapp/app.js # Command to run.
[Install]
WantedBy=multi-user.target
notes:
- https://unix.stackexchange.com/questions/368100/where-to-place-user-created-systemd-unit-files
- https://stackoverflow.com/questions/29739715/how-can-i-run-pm2-on-a-certain-node-version
- https://stackoverflow.com/questions/29349684/how-can-i-specify-the-required-node-js-version-in-package-json
Deploying an Node.js App to Personal Server in Production with Github Actions and PM2
https://medium.com/@g.c.dassanayake/deploying-a-nodejs-application-using-github-actions-e5f4bde7b21b requirements: github account, server,
- create a local node.js application
- create a github repository and push initial application
- create github workflow file
- create github actions self hosted runner
- configure pm2 to daemonize program
- open port to the web through port routing
other things to learn
- nginx and reverse poxy
PM2
ERROR: How to daemonize application using pm2 and yarn SOLUTION:
Silencing React.Js warnings
ERROR: When running cicd, get “Treating warnings as errors because process.env.CI = true” SOLUTION: