0
votes

I am getting this error when i run my program

Error:

ReferenceError: option is not defined at C:\Users\H00422000\desktop\newsletter-signup\app.js:39:33 at Layer.handle [as handle_request] (C:\Users\H00422000\desktop\newsletter-signup\node_modules\express\lib\router\layer.js:95:5) at next (C:\Users\H00422000\desktop\newsletter-signup\node_modules\express\lib\router\route.js:137:13) at Route.dispatch (C:\Users\H00422000\desktop\newsletter-signup\node_modules\express\lib\router\route.js:112:3) at Layer.handle [as handle_request] (C:\Users\H00422000\desktop\newsletter-signup\node_modules\express\lib\router\layer.js:95:5) at C:\Users\H00422000\desktop\newsletter-signup\node_modules\express\lib\router\index.js:281:22 at Function.process_params (C:\Users\H00422000\desktop\newsletter-signup\node_modules\express\lib\router\index.js:335:12) at next (C:\Users\H00422000\desktop\newsletter-signup\node_modules\express\lib\router\index.js:275:10) at serveStatic (C:\Users\H00422000\desktop\newsletter-signup\node_modules\serve-static\index.js:75:16) at Layer.handle [as handle_request] (C:\Users\H00422000\desktop\newsletter-signup\node_modules\express\lib\router\layer.js:95:5)

Code:

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


app.use(bodyParser.urlencoded({extended:true}));
app.use(express.static("public"));
app.get("/",function(req,res){
  res.sendFile(__dirname +"/news.html");
});
app.post("/",function(req,res){
var f1=req.body.f1;
var l1=req.body.l1;
var e1=req.body.e1;

var data={
  members: [
    {
      email_address:e1,
      status:"subscribed",
      merge_feilds:{
        FNAME:f1,
        LNAME:l1
      }
    }
  ]

};
const url='https://us10.api.mailchimp.com/3.0/lists/f0c448a295';
const options = {
  method: "post",
  auth:"mihr:229d66f728411db957eaae8894911467-us10"
}


const jsonData=JSON.stringify(data);
const request=https.request(url,option,function(response){

if (res.statusCode===200)
{res.send("suceeedede")}
else{res.send("errororrrororo")}

response.on("data",function(data){
  console.log(JSON.parse(data));
});


});

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

//229d66f728411db957eaae8894911467-us10
//f0c448a295
});


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

2 Answers

0
votes

you made a small typo:

const request=https.request(url,options,function(response){

if (res.statusCode===200)
{res.send("suceeedede")}
else{res.send("errororrrororo")}

response.on("data",function(data){
  console.log(JSON.parse(data));
});


});

this should work ;)

0
votes

You declare a variable as options but reference it as option so it will throw an error of option is not defined

const request=https.request(url,options,function(response){})