Nodejs HTTPS request failing on server but working locally (netlify dev)

I am trying to use firebase api to send notifications to IOS phones. The request works when I run it locally using netlify dev but when I push to the live server it fails. Sometimes with an error:

    const https = require('https')
    const postData = JSON.stringify({
        "to": "DEVICE_TOKEN",
        "notification": {
            "title":  "Method 1",
            "body":  "This alert was sent through helloHTTPS"
        }
    })

    const options= {
        hostname: 'fcm.googleapis.com',
        path: '/fcm/send',
        method: 'POST',
        headers:  {
            'Content-Type': 'application/json',
            'Authorization': 'key=FCM_KEY'
        }
    }

    // METHOD 1 - CHUNKING
    const req = https.request(options, (res) => {
        let body = ''
        console.log("Status Code: ", res.statusCode)

        res.on('data', (chunk) => {
            body += chunk
        })

        res.on('end',() => {
            console.log("Body: ", JSON.parse(body))
        })
    })

    req.write(postData)
    req.end()

What is the error that you get?