-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.js
More file actions
48 lines (40 loc) · 1.15 KB
/
app.js
File metadata and controls
48 lines (40 loc) · 1.15 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
//WebApp
const express = require("express");
const request = require("request");
const bodyParser = require("body-parser");
const app=express();
app.use(express.static('static'));
app.use(bodyParser.urlencoded({extended:true}));
app.get('/', function(req,res) {
res.sendFile(__dirname + '/signup.html');
});
app.post('/', function (req,res) {
var fname=req.body.fname;
var lname=req.body.lname;
var email=req.body.email;
var data={
members:[
{
email_address:email,
status:"subscribed",
merge_fields:{
FNAME:fname,
LNAME:lname
}
}
]
};
var jsondata=JSON.stringify(data);
var options={
url:"https://us20.api.mailchimp.com/3.0/lists/{listid}",
method:"POST",
headers: { "Authorization":"{anystring} {API-Key-usX}"},
body:jsondata
};
request(options, function(error, response, body) {
res.sendFile(__dirname+'/success.html')
});
})
app.listen(process.env.PORT || 8080, function () {
console.log("Runing at port 8080!!");
});