-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
37 lines (26 loc) · 753 Bytes
/
Copy pathindex.js
File metadata and controls
37 lines (26 loc) · 753 Bytes
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
const express = require('express');
const cors = require('cors');
const app = express();
app.use(cors());
const path = require('path');
const port = process.env.PORT || 3000;
const apiData = require("./indiaPincode.json");
app.use(express.static(path.join(__dirname, '/public')))
app.get("/", (req, res) => {
res.send("Namaste");
});
// app.get("/pincode", (req, res) => {
// res.send(apiData)
// });
app.get("/pincode", (req, res) => {
const {Pincode} = req.query;
let results = [...apiData];
if (Pincode) {
results = results.filter(r => +r.Pincode === +Pincode);
}
res.json(results);
});
app.listen(port, ()=>{
console.log("Namaste from terminal");
})
// http://localhost:3000/pincode?Pincode=828112