Giter Club home page Giter Club logo

24-7_hosting_replit's Introduction

24/7 Free Hosting with Repl.it

How do I get free 24/7 hosting with replit? Here's how.

If this repository helps you in any way, give it a ⭐:

⚠️ Warning: This only works for Node.JS or HTML, CSS, JS repls.

💡 Tip: repl.it is great for testing out projects before lauching to the masses.

Index

Creating a Repl

Assuming you've already created a replit account, let's make a repl:

💡 Tip: If you already have a repl, go to the next section.

  1. Go to replit.com/~
  2. Create a repl by clicking the ➕ sign under the 'Create' section:
  3. Select Node.JS as your template (or HTML, CSS, JS for a site):

For Node.JS 16+, fork this repl instead of creating a new one!

  1. Give it a name, or stick with the one that is auto generated:
  2. Click "Create Repl":

Hosting

Install Packages

  1. Run npm init -y in the Shell
  2. Run this in the Shell to install the dependencies:
npm install express ping-monitor

⚠️ Warning: It is very important that you use the Shell tab for this:

If you are on mobile, then you probably won't see the Shell tab, in that case, go into "View Desktop Mode". Learn how below:

After that, you should be able to access Shell as normal. When you are done using the Shell, I recommend going back to regular view, as the sizing of the page gets a bit weird on Desktop mode.

index.js

Put this code in your index.js file for the Node.JS template, or script.js for the HTML, CSS, JS template:

const keepAlive = require('./server');
const Monitor = require('ping-monitor');

keepAlive();
const monitor = new Monitor({
    website: '',
    title: 'NAME',
    interval: 2
});

monitor.on('up', (res) => console.log(`${res.website} its on.`));
monitor.on('down', (res) => console.log(`${res.website} it has died - ${res.statusMessage}`));
monitor.on('stop', (website) => console.log(`${website} has stopped.`) );
monitor.on('error', (error) => console.log(error));

💡 Tip: If you already have code in your index.js file, just put this code at the bottom of the code, or where ever you feel it looks best.

server.js

  1. Create a file called server.js:

  2. Paste-in this code:

const express = require('express');
const server = express();

server.all('/', (req, res) => {
    res.send('<h2>Server is ready!</h2>');
});

module.exports = () => {
    server.listen(4000, () => {
        console.log('Server Ready.');
    });
    return true;
}

💡 Tip: See where I put 4000, it is recommended you change that if you are using multiple repls. For example, you can do 1000, 2000, 3000, or whatever else. This is just a port.

Run It

Click the 'Run' button:

UptimeRobot

We will be using UptimeRobot as the monitoring system.

  1. Copy the URL of the website that shows when you run the repl. If you are on mobile, this will be on the "Output" tab; on Desktop, you'll see it in the upper right corner of your screen:
  2. Go to uptimerobot.com and create a new account:


    Don't forget to check your email!
  3. After clicking the link in your email, it should take you to the dashboard. Here, you can create a new monitor:
  4. Select these settings, then save (you'll need to double click the "Create Monitor" button):

    "https://replname.yourusername.repl.co" should be replaced with the URL we copied from our repl earlier.

Profit

Run your repl, and now your bot/website/project will be hosted 24/7. Note that this is free hosting, so obviously it isn't perfect. But it is certainly good enough to experiment with!
Good luck and have fun building your project.

pssst: If you need any help or want to chat with fellow developers join our Discord Server

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.