This packages identify if a server is alive and can check if a service is running on this server doing a request that you have to configure easily, for example with fetch-node module, just follow the instructions.
Welcome to my repository, you can help me validating my aptitudes on LinkedIn.
LinkedIn: https://www.linkedin.com/in/jordi-piqueras-50b439b9/
First of all you need to install node.js and npm to run this code. You can do it on a Linux, MacOs, Windows even in your mobile phone like me.
npm install is-server-alive
Before use it you need to create a Telegram bot, follow the instructions.
- On your Telegram App clic the pencil to create a new message.
- On your Telegram App clic the magnifying glass to search a user and write: @botfather
- Go to the chat and use commands with the slash symbol / to execute it
- Create a new bot: /newbot
- Store the token on your config value.
- Install the code with npm install.
- Use the code of showMyChatId to get your chatId, while is executing then write something to the bot, this will show you a message with your id, put it on the code.
const showMyChatId = require('is-server-alive').showMyChatId
const token = 'INTRODUCE_YOUR_BOT_TOKEN_HERE'
showMyChatId(token)
const isServerAlive = require('is-server-alive').isServerAlive
const config = {
token: 'INTRODUCE_YOUR_BOT_TOKEN_HERE',
chatId: INTRODUCE_YOUR_CHAT_ID,
targets: ['google.com', '121.113.113.41'], // Array of strings: Domains and URLs
options: {
timeout: 5, // Time to wait for the ping response.
extra: ["-i 2"], // Number of ping petitions.
},
intervalTimeout: 5000, // Interval of the request against the server.
}
isServerAlive(config)
After complete the information of your bot/chat install pm2 and prepare for monit your aplication:
npm install pm2
You can put this scripts on your package.json:
"scripts": {
"start": "pm2 start your_file",
"stop": "pm2 stop your_file_name",
"status": "pm2 status",
"list": "pm2 list",
"monit": "pm2 monit",
"kill": "pm2 kill"
}
I give an special mention to the GitHub community:
- node-telegram-bot-api: https://github.com/yagop/node-telegram-bot-api
- Ping: https://github.com/danielzzz/node-ping
- P2m: https://github.com/Unitech/pm2
- Telegram API: https://core.telegram.org/