Understanding web services with Node JS

Hey everyone. First time using render.

I have a little script that runs every so often then saves data to firebase. The best fit for this would be the “web service”, right? I’m doing that, and not getting any errors, but I have some console logs to show each step when the script runs, and they never show.

They should show in the logs, right? Any idea what might be going on? I have my build command as npm install , then my start command and node index.js , just as is working locally. Anything come to mind that I’m not thinking of? Happy to share any info that might be helpful. Again - no errors, and the build is successful.

Thanks!

Hi Trey,

Thanks for reaching out.

A Web Service is intended for use with code that has a web server and responds to http requests, often using something like Express in Node.

From your description, it doesn’t sound like you’re running a website. If you need to run a script at regular intervals, that sounds like a Cron Job.

If I’ve misunderstood, or you still require assistance, please could you share some specific examples of what you’re trying to achieve/issues you’re having, e.g. any logs/errors/output, URLs, service name/ID, reproduction steps, etc. If you don’t want to share these details on the community forum, please feel free to raise a ticket with support@render.com

Alan

Thanks for the response, Alan! I guess I was confused because I am using this as sort of a middleware for my site - to save the data to firebase that I’ll use on the front end, but that makes total sense.

Right now, I’m just using a couple setInterval()'s to call 2 different functions every so often. Would I be correct in assuming that if I switch the project to a cron job I won’t need the setInterval() and can determine which functions to call and how often from the render dashboard? Or how would that work? I’ll start checking the docs now.

Thanks again!

Would I be correct in assuming that if I switch the project to a cron job I won’t need the setInterval() and can determine which functions to call and how often from the render dashboard?

Yes, you would :slightly_smiling_face:

Alan

If you want to run a script repeatedly on some sort of schedule, that’s what Cron Jobs are for. They don’t stay running in the background, just spin up, execute the given script, then go away (which saves money over a server that has to sit around counting down the seconds). If you want 2 functions, you probably set them up as 2 separate jobs (they can get their own schedules, scripts, environment variables).

If you also need a server (a back end that needs to listen for requests 24/7), then you could bundle into it using setInterval like you described. That would save a couple cents per month, but it would mean you can’t auto-scale etc (it could be a mess if you have 2 at some point).

Thanks! I do have 2 functions but it’s fine if they run once at the same time. They’re both in my index.js file. So I could just set up a cron to run once every, say, hour and it’ll run and both functions will be called? So my build command would just be node index.js?

You say they go away after being called - how does that work? It just runs, waits for the action to finish, then stops all processing until the next hour?

Yes, the container is spun up to run the set command, when the process exits the container is spun down until the next set interval.

Alan

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.