-
Notifications
You must be signed in to change notification settings - Fork 4
/
app.js
30 lines (25 loc) · 666 Bytes
/
app.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
const express = require("express");
const app = express();
app.use(express.urlencoded({ extended: false }));
app.use(express.json());
const runApplication = () => {
app.listen(3000);
console.log("app is running");
};
async function getInfoIpAddress(req, res) {
const ip = await req.body.ip;
if (!req.body.ip || req.body.ip.length < 4) {
return await res.json({
success: false,
error: "ip is required",
});
}
const request = await fetch(`http://ip-api.com/json/${ip}`);
const result = await request.json();
return res.json({
success: true,
ipAddress: result,
});
}
app.post("/", getInfoIpAddress);
runApplication();