How to restart Render web service automatically

Posted on May 29, 2022

If you have a web service hosted on and previously you were on, you should be aware that the former won't restart the service each day as Heroku is used to do.

Depending on each situation, to me restarting sometime the service is a good practice to keep the process healthy.

Thankfully, provides an API for each service, thus, restarting it programmatically is just an API call away.

Here my solution: I use a Netlify scheduled lambda function that calls the API to restart my service.

This is the code of the Netlify scheduled function that runs every day and restart my service:

const axios = require('axios')
const { schedule } = require('@netlify/functions')

const handler = async (event, context) => {
    const res = await axios(`${process.env.RENDER_SERVICE_ID}/deploys`, {
        method: 'post',    
            'Accept': ' application/json',
            'Content-Type': 'application/json',
            'Authorization': 'Bearer ' + process.env.RENDER_SERVICE_TOKEN
        data: {}
    const src =
    return {
      statusCode: 200,
      body: JSON.stringify(src)

exports.handler = schedule("@daily", handler)