| const express = require("express"); |
|
|
| const app = express(); |
|
|
| |
| const PORT = process.env.PORT || 5900; |
|
|
| |
| const countries = [ |
| { name: "Moldova", code: "+373" } |
| ]; |
|
|
| |
| let phoneStore = [ |
| "+37368177131", |
| "+37368177131", |
| "+37368177131" |
| ]; |
|
|
| |
| app.get("/list-country-code", (req, res) => { |
| res.json({ |
| success: true, |
| data: countries |
| }); |
| }); |
|
|
| |
| app.get("/list-phone-number", (req, res) => { |
| res.json({ |
| success: true, |
| data: phoneStore |
| }); |
| }); |
|
|
| |
| app.get("/generate-phone", (req, res) => { |
| const country = req.query.country || "373"; |
| const count = parseInt(req.query.count || "5"); |
|
|
| const generated = []; |
|
|
| for (let i = 0; i < count; i++) { |
| |
| const number = Math.floor(10000000 + Math.random() * 90000000); |
| generated.push(`+${country}${number}`); |
| } |
|
|
| |
| phoneStore = phoneStore.concat(generated); |
|
|
| res.json({ |
| success: true, |
| country: `+${country}`, |
| generated |
| }); |
| }); |
|
|
| |
| app.get("/", (req, res) => { |
| res.send("Phone Generator API running on port " + PORT); |
| }); |
|
|
| app.listen(PORT, () => { |
| console.log(`Server running on http://localhost:${PORT}`); |
| }); |