Backend hosted on an EC2 Amazon instance to serve as backend to the react native application Dota2CountersReactNative.
- Install PM2 on your server
npm install pm2@latest -g
➡️ PM2
it's a package that is going to run the process in the background.
- Go to your
server.js
folder and run
pm2 start server.js
➡️ If you have problems and need to add node params, you can do something like:
pm2 start server.js --node-args="--max-http-header-size=16384"
Other configs to pm2:
pm2 status
pm2 restart {index}
cat /proc/sys/net/ipv4/ip_forward
➡️ verify if port forwarding is enabled (1: enabled, 0: disabled)- if disabled (0), then:
sudo nano /etc/sysctl.conf
- uncomment the following line:
net.ipv4.ip_forward
sudo sysctl -p /etc/sysctl.conf
(to enable changes)
cat /proc/sys/net/ipv4/ip_forward
➡️ verify if port forwarding is enabled (1: enabled, 0: disabled)- set port forwarding:
sudo iptables -A PREROUTING -t nat -i eth0 -p tcp --dport {PORT_OF_YOUR_INSTANCE} -j REDIRECT --to-port {PORT_OF_YOUR_SERVER_APPLICATION}
For e.g.:
sudo iptables -A PREROUTING -t nat -i eth0 -p tcp --dport 80 -j REDIRECT --to-port 8080
where: - {PORT_OF_YOUR_INSTANCE} is the port opened on your machine (usually 80, 443, 22 ...) - {PORT_OF_YOUR_SERVER_APPLICATION} is the port that you're listening on your application (on server.js for node) 5) Now open your firewall to that port
sudo iptables -A INPUT -p tcp -m tcp --sport {PORT_OF_YOUR_INSTANCE} -j ACCEPT
For e.g.:
sudo iptables -A INPUT -p tcp -m tcp --sport 80 -j ACCEPT)
And:
sudo iptables -A OUTPUT -p tcp -m tcp --dport {PORT_OF_YOUR_INSTANCE} -j ACCEPT
- Enable cron: sudo systemctl enable cron
- Type crontab -e and then enter
- select nano as your editor (usually option 1)
- Set your crontab service (go to cron guru for examples)
30 03 * * * python3 /home/ubuntu/dota2cp/dotabuff_scrapper.py
It'll run dotabuff_scrapper.py everyday at 03:30am.
➡️ (don't forget the "/" before the path in "/home...", otherwise will not work)
➡️ (always test before, in other words, test on the terminal: python3 /home/ubuntu/dota2cp/dotabuff_scrapper.py)