A simple NodeJs Script which checks if your ETH Node is alive

At QuikNode, we always think of our customers and the problems they encounter using Web3. We recently started noticing that some were facing a problem with monitoring their Ethereum Node status.

The team quickly decided to write a script which would help customers (or anyone, really) monitor their Ethereum node connection status. Is the Node responding to RPC requests or not?

buddies2705/Eth-Ping
Checking if your Ethereum node is alive or not? . Contribute to buddies2705/Eth-Ping development by creating an account on GitHub.

What does the Script do?

The script continuously calls “eth_blockNumber” every 15 seconds and checks if the Node is responding properly or not. If something is off, you can have it send you an email notification, so you can take appropriate action.

Configuration

We have added a config.json which you need to change accordingly.

  • rpcURL — Add your Node RPC URL
  • email — Add Your Email
  • password — Add Your Email Password
  • recipient- Add recipients URL
  • emailSubject — Add email subject
  • emailText — Add email Text
  • emailHtml — Add email text in HTML (if this is configured, our script will ignore above plain email text (emailText))

Allow less secure app if you want to use Gmail mail service; follow this doc and Change account access for less secure apps

We are using Gmail, so you need to change a security setting for your Gmail account (please check this doc). Also, you need to change a few variables, such as adding your node URL and Gmail username & password. Also, change ‘from’ and ‘to’, and other things accordingly related to the mail which will get sent when the script detects that your node is down.

Send Test Email

Once the configuration is done we can test our email setup by running below command.

npm run testmail

How to run it?

You need to install NodeJs and clone the repository.

git clone https://github.com/buddies2705/Eth-Ping
npm install
npm start

We recommend you to use PM2 to run above script, as it restarts the script if it gets crashed for XYZ reason.

Conclusion

We will be tweaking it over time and encourage you to use this script. Feedbacks, Comments, and Pull Requests are welcome!

About QuikNode

QuikNode is building infrastructure to support the future of Web3. Since 2017, we’ve worked with hundreds of developers & companies, helping scale their Dapps and providing high-performance Ethereum nodes. We’re working on something interesting from the past few months and will be launching soon, so subscribe our newsletter for more updates!! 😃