I am working on my newsletter project using Mailchimp API, it works but I can’t redirect to a failure page if the status code is not 200, the browser says localhost refused to connect meanwhile success page redirection works great.
here’s my code:
app.post("/", async(req, res, next)=>{
const {fName, lName, email} = req.body.user;
const response = await mailchimp.lists.addListMember("List_ID", {
email_address: email,
status: "subscribed",
merge_fields:{
FNAME: fName,
LNAME: lName,
},
});
if(res.statusCode === 200){
res.sendFile(__dirname + "/success.html");
}
else{
res.sendFile(__dirname + "/failure.html");
}
});