-
Notifications
You must be signed in to change notification settings - Fork 0
/
contacts.js
51 lines (49 loc) · 1.16 KB
/
contacts.js
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
48
49
50
51
// contacts data is hardwired into memory
var express = require("express");
var app = express();
const fetch = require("node-fetch");
app.use(express.json());
// store contacts in an arrays
var contacts = [
{
name: "peter parker",
age: 21,
email: "[email protected]",
courses: [
{ number: "1.00", name: "engr comp" },
{ number: "3.00", name: "intro bio" },
],
},
{
name: "bruce wayne",
age: 32,
email: "[email protected]",
courses: [
{ number: "2.00", name: "intro ME" },
{ number: "3.00", name: "intro MS" },
],
},
{
name: "diana prince",
age: 25,
email: "[email protected]",
courses: [
{ number: "2.00", name: "intro arch" },
{ number: "1.00", name: "intro chem" },
],
},
];
app.get("/", function (req, res) {
res.send("<h1> Goodbye Routes: try POST to /contact and GET /contacts </h1>");
});
// list all contacts
app.get("/contacts", function (req, res) {
res.json(contacts);
});
// add a contact
app.post("/contact", (req, res) => {
contacts.push({ name: req.body.name, email: req.body.email });
res.json(req.body);
});
app.listen(3000);
console.log("Running on port 3000");