A
A
Alexal32021-12-11 17:23:20
Software Deployment
Alexal3, 2021-12-11 17:23:20

How to set up a VPS for a Telegram bot on NodeJS?

There is a Telegram bot on NodeJS. It needs to be deployed to a VPS server.

How to do it correctly, namely:

1) How to make the bot work not as root? And is it necessary? I'm running the bot using the pm2 package. As you can see, if you write pm2 status, the bot starts as root (see screenshot).

2) How to correctly and safely set environment variables? They are currently stored in the root user's .bash_profile file.

3) How to set up a convenient deployment of updates for the bot? Let's say I updated the bot code and pushed the changes to GitHub. How can I make code changes automatically saved to the VPS?

4) In what folder should the Telegram bot be located?

61b4b3ac65add283095468.png

Answer the question

In order to leave comments, you need to log in

1 answer(s)
W
wonderingpeanut, 2022-03-24
@wonderingpeanut

Greetings.
Issues 1 and 2 can be solved with docker. In the dockerfile, you can specify environment variables and change user rights. Without docker in the VM, you will need to create a user without root rights and transfer the rights to the software folder to this user (chown). Environments are usually stored in an .env file. Access to them from the node is done using the dotenv lib.
Problem 3 is solved using github actions. You will need to write an action that will work when the branch changes (push). This action will send a new version of the bot and the necessary restart commands to the vps.
ps. I myself have never solved the problems that you encountered, so I ask you to treat everything that I wrote with a grain of salt)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question