File size: 1,340 Bytes
dfe5d44 | 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 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 | const express = require("express");
const app = express();
// Fixed config (no dotenv)
const PORT = process.env.PORT || 5900;
// Country codes database (extend anytime)
const countries = [
{ name: "Moldova", code: "+373" }
];
// In-memory storage
let phoneStore = [
"+37368177131",
"+37368177131",
"+37368177131"
];
// Get country codes
app.get("/list-country-code", (req, res) => {
res.json({
success: true,
data: countries
});
});
// List stored phone numbers
app.get("/list-phone-number", (req, res) => {
res.json({
success: true,
data: phoneStore
});
});
// Generate phone numbers dynamically
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++) {
// simple random 8-digit number
const number = Math.floor(10000000 + Math.random() * 90000000);
generated.push(`+${country}${number}`);
}
// save into store
phoneStore = phoneStore.concat(generated);
res.json({
success: true,
country: `+${country}`,
generated
});
});
// Health check
app.get("/", (req, res) => {
res.send("Phone Generator API running on port " + PORT);
});
app.listen(PORT, () => {
console.log(`Server running on http://localhost:${PORT}`);
}); |