glitchy-ping
v0.3.2
Published
Keep your Glitch projects awake
Downloads
2
Maintainers
Readme
glitchy-ping
Keep your Glitch projects awake with the help of this tiny package!
Note: if you're using release 0.1.0 or release 0.2.0, please see the Known Issues section!
Highlights
- Easy to use
- 0 dependencies
- Lightweight
Motivation
As explained in Glitch Help Center, projects go to sleep after 5 minutes of inactivity and wake again on requests. This might be fine for websites, but for applications like bots for instant messaging services, it's an impractical restriction.
Usage Instructions
First, require the module:
const glitchyPing = require("glitchy-ping");
Then, put this in the section of code that is run when your application starts up:
glitchyPing.pingURL(`https://${process.env.PROJECT_DOMAIN}.glitch.me/`);
And that's it! Your project should stop feeling sleepy now, doesn't matter if it is public or private.
Note that if you don't provide any URLs, glitchy-ping will first check the existence of the environment variable PROJECT_DOMAIN
, then use it to construct the URL of your project. So if you feel like it, you can make the code even shorter:
require("glitchy-ping").pingURL();
Awesome!
Advanced Options
Interval:
By default, a GET request is made to the given URL every 4 minutes and 30 seconds. If you want to change the interval, pass a number in as the second argument.glitchyPing.pingURL("https://your-project-name.glitch.me/", 180000); // 180000ms == 180s == 3min
Mock browser:
Although this package is meant for Glitch projects, you can use it elsewhere too. Some websites/APIs require the request header to contain a valid User Agent.
By default, a GET request is sent without one. If you want the request header to contain a User Agent, you can pass a boolean in as the third argument.glitchyPing.pingURL("https://url-to-be-pinged.com/", null, true); // This would make the request look like it's made from a normal browser
Multiple URLs:
If you need to keep multiple projects awake, you can pass in an Array of URLs as the first argument.glitchyPing.pingURL(["https://project1.glitch.me/", "https://project2.glitch.me/", "https://project3.glitch.me/"]);
Important Note
Although this prevents your project from sleeping, it doesn't bypass the restriction where projects must stop after running for 12 hours. A solution would be to create another project on Glitch, and set them to "ping" each other.
FAQ
Q: What's the benefit of using this package over other viable options?
A: You don't have to register for 3rd party services like Uptime Robot just to keep your Glitch projects awake. See Important Note to keep your application running for over 12 hours.Q: What's the benefit of adding this tiny package instead of writing something myself?
A: You can definitely write it yourself if you've read the documentation for Node.js HTTP(S) API, but it doesn't look pretty and also makes things potentially harder to maintain.
Packages Comparison
Here is how glitchy-ping compares to other similar packages available on NPM:
| | koa-glitch-keepalive | express-glitch-keepalive | glitchup | glitchy-ping | | --- | --- | --- | --- | --- | | Node.js | >=8 | >= 8 | 6.9.x | >=7.6.0 | | Dependencies | 0 | 0 | 1 | 0 | | Dependency state | N/A | N/A | Out of date | N/A | | Usable with | Koa | Express | Anything | Anything | | Size | 2.5 kB | 3.7 kB | ??? | ~15 kB | | Configurable URL | No | Path only | Path only | Yes | | Configurable interval | No | Down to minutes | No | Yes | | Multiple URLs | No | No | No | Yes |
glitchy-ping is inspired by glitchup.
Known Issues for Older Releases
Here are the known issues for release 0.1.0 and release 0.2.0. If you're using them, please update immediately!
For 0.1.0:
- Any URLs using HTTP protocol will cause glitchy-ping to fail with TypeError [ERR_INVALID_PROTOCOL]
- Attempting to use Node.js whose version is < 10.9.0 will cause glitchy-ping to fail with TypeError [ERR_INVALID_ARG_TYPE]
- Attempting to use Node.js whose version is < 7.0.0 may cause glitchy-ping to fail with SyntaxError
For 0.2.0:
- The Node.js version compatibility is incorrectly listed as "^7.0.0", the correct version compatibility should be >=10.9.0
- Attempting to use Node.js whose version is < 10.9.0 will cause glitchy-ping to fail with TypeError [ERR_INVALID_ARG_TYPE]
- Attempting to use Node.js whose version is < 7.6.0 will cause glitchy-ping to fail with TypeError: url.format is not a function
Since release 0.3.0, the listed issues have been fixed and the Node.js version compatibility has been corrected, sorry for the inconvenience.
Disclaimer
This package is not provided by or supported by Glitch, Inc. Please use responsibly, the available resource on Glitch is meant for everyone, not just for you.
License
This project is licensed under MIT License.
Copyright (c) 2018-2019 LightWayUp
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.