const { response } = require("express");
const express = require("express");
const https = require("https");
const bodyParser = require("body-parser");
const { url } = require("inspector");
const e = require("express");
const app = express();
const port = 3000;
//To use css or images we need to use a express static fucntion
//For this we will create a folder named public and add all our images and css files into that folder.
app.use(express.static("public"));
app.use(bodyParser.urlencoded({ extended: true }));
app.get("/", (req, res) => {
res.sendFile(__dirname + "/signup.html");
});
app.post("/", function (req, res) {
var firstName = req.body.fName;
var lastName = req.body.lName;
var email = req.body.email;
console.log(firstName, lastName, email);
const mailchimp = require("@mailchimp/mailchimp_marketing");
mailchimp.setConfig({
apiKey: "XXXX-us21",
server: "us21",
});
async function run() {
const response = await mailchimp.lists.batchListMembers("XXXX", {
members: [
{
email_address: email,
status: "subscribed",
merge_fields: {
FNAME: firstName,
LNAME: lastName,
},
},
],
});
console.log("response.status: ", res.statusCode); // ️ 200
if (res.statusCode === 200) {
res.send("Added Successfully");
} else {
res.send("Error signing up");
}
}
run();
I am unable to process the mail chimp status code while running this code, regardless if the connection was successful or not. I want to display a message indicating whether or not the data entered by the user into the html form was properly submitted. Therefore, when I use the response(res) method, I can process the success message, but it does not work if it has errors.