Node Fetch Request Fails on Server: Unable to Get Local Issuer Certificate
Try using the following:
process.env["NODE_TLS_REJECT_UNAUTHORIZED"] = 0
Hosting has probably some issue with list of certificate authorities... as a workaround you could try to ignore certificate validity.
const fetch = require('node-fetch')const https = require('https')const express = require('express')const app = express()const agent = new https.Agent({ rejectUnauthorized: false})//-- HTTP --app.get('/test-no-ssl', function(req, res){ fetch('http://jsonplaceholder.typicode.com/users') .then(res => res.json()) .then(users => { res.send(users) }).catch(function(error) { res.send(error) })})//-- HTTPS --app.get('/test-ssl', function(req, res){ fetch('https://jsonplaceholder.typicode.com/users', { agent }) .then(res => res.json()) .then(users => { res.send(users) }).catch(function(error) { res.send(error) })})app.listen(3003, () => console.log('Listening on port 3003...'))
Note: this has security implications, making https insecure the same way as http.