malxau/yori

throw er; // Unhandled 'error' event

hotboyer opened this issue · 2 comments

const express = require("express");
const bodyParser = require("body-parser");
const request = require("request");
const https = require("https");

const app = express();

app.use(express.static("public"));
app.use(bodyParser.urlencoded({extended: true}));

app.get("/", function(req, res) {
res.sendFile(__dirname + "/signup.html")
});

app.post("/", function(req, res) {
const firstName = (req.body.first_name);
const lastName = (req.body.last_name);
const email = (req.body.email);
const data = {
members: [
{
email_address: email,
status: "subscribed",
merge_fields: {
FNAME: firstName,
LNAME: lastName,
}

        }
    ]
};

const jsonData = JSON.stringify(data);
const url = "https://us13.api.mailchimp.com/3.0/lists/e598f4082b";

const options = {
    method: "POST",
    auth: "Pinnacle:c72360e0a9e0b0039a7e9874ce26ee88-us13"
}

const request = https.get(url, options, function(response) {
    response.on(data, function (data) {
        console.log(JSON.parse(data));
    })
});
console.log(request)

request.write(jsonData); 
request.end();

})

app.listen(3000, function() {
console.log("server is running on port 3000");
})

I ran this code and I got the error "throw er; // Unhandled 'error' event " on my hyper is terminal

i've been stuck on this code for 2 days now 😥😥😪