How Do I Make A Repl Run At a Set Time?

how do i make it so where it will type good afternoon at 12:00 pm please tell me i would be happy and if you do thanks for the help

Replit doesn’t have a feature to run the code at a set time. You didn’t say which language you’re using but what you’re going to need is this:

  1. A Repl which is either Always On or Deployed
  2. A code which runs a forever loop
  3. Inside this forever loop, a function checks the current time
  4. Inside this forever loop, if the current time matches a given time, execute a certain function

I would put a delay between time queries so that it isn’t constantly checking the time. Maybe check once a minute or something. The reason why time checking is necessary is because even Replit’s most reliable methods of keeping a Repl on will not guarantee 24/7/365 uptime, and so it cannot rely on simple delays and counters to keep time.

4 Likes

can you like show me a photo for an example

A photo of what? Screenshot? Could you tell me what language you want to use and I’ll determine whether or not I know how for that language?

2 Likes

english that’s the language

What programming language? Python? JavaScript? C++?

1 Like

No but you can do that with code. Depending on the programming language. In Python there’s a schedule module.

1 Like

im sure it is java script

how do i check it again

Front end (website) or back end (NodeJS)?

1 Like

Your Repl should say although the key words and syntax should provide a good clue. Looking at your profile your only Repl is NodeJS.

1 Like

well i don’t know much so i don’t know what your talking about?

Frontend JavaScript (JS) is what runs on a website when you load it, click buttons on it, etc. Backend JS runs in the terminal and is used to host servers. The only project I see on your Replit profile is NodeJS which is a backend JS.

1 Like

now i remember yes it is node js

1 Like

What project are you trying to create? Is it this one or something else?

1 Like

yes that one and also your very good at coding im sure

Does this help?

Use the node-cron library

const cron = require('node-cron');

cron.schedule('0 12 * * *', () => {
  console.log('Good afternoon');
});

Runs in the timezone the server is set in.

For specific timezones

const cron = require('node-cron');

cron.schedule('0 12 * * *', () => {
  console.log('Good afternoon');
}, {
  scheduled: true,
  timezone: "America/New_York"
});

The server is probably in California. I’d use the code that allows you to specify the timezone.

1 Like

ok ig let’s see soon😀