I keep getting the following error when trying to use the https library at work, I have tried a few different examples to make the request along with different urls, I figured it could be a proxy issue so configured a .bat file with env variables and then ran npm start but Im getting the same issue shown in the title.var express = require('express');var cors = require('cors');const dotenv = require('dotenv');const https = require('https');const app = express();dotenv.config();app.use(cors());var options = { host: 'jsonplaceholder.typicode.com',path: '/todos/1'}; https.get(options, (resp) => {let data = '';// A chunk of data has been recieved.resp.on('data', (chunk) => {data += chunk; });// The whole response has been received. Print out the result.resp.on('end', () => {console.log(JSON.parse(data)); });}).on("error", (err) => {console.log("Error: " + err.message);});app.get('/hello', (req, res) => {res.send('Hello World!');});app.listen(process.env.PORT, () =>console.log(`Example app listening on port ${process.env.PORT}`),);
Submitted December 05, 2019 at 08:52PM by AllHailTheCATS
No comments:
Post a Comment