A RESTful API for discovering countries and cities worldwide, with geolocation features and Wikipedia data integration.
Finda.city is a geographic data API that provides information about countries and cities around the world. It features IP-based geolocation, proximity search, and integrates with Wikipedia to provide enriched data about locations.
- 🌍 Country Information: Get data about countries including population, life expectancy, coordinates, and capital cities
- 🏙️ City Search: Find cities by name, country, or population range
- 📍 Proximity Search: Find nearby cities based on IP geolocation
- 📊 Wikipedia Integration: Automatically enriches data with information from Wikidata
- 🗄️ MongoDB Database: Efficient data storage with geospatial indexing
- ⚡ Built with Bun: Fast runtime and package management
- Runtime: Bun
- Framework: Express.js
- Database: MongoDB with Mongoose
- Language: TypeScript
GET /health
Returns the health status of the API.
Response:
{
"ok": true
}GET /countries
Returns a list of all countries in the database.
Response:
[
{
"CountryLabel": "spain",
"country": "Spain",
"CapitalLabel": "Madrid",
"iso2": "ES",
"population": 47450795,
"lifeExpectancy": 83.2,
"continent": "Europe",
"lat": 40.4,
"lon": -3.7,
}
]POST /country
Get information about a specific country.
Request Body:
{
"country": "spain"
}Response:
[
{
"CountryLabel": "spain",
"country": "Spain",
"CapitalLabel": "Madrid",
"iso2": "ES",
"population": 47450795,
"lifeExpectancy": 83.2,
"continent": "Europe",
"lat": 40.4,
"lon": -3.7,
}
]GET /getIdWiki
Admin endpoint to update country data from Wikidata (life expectancy, wiki IDs, etc.).
GET /nearme
Returns the 5 closest cities to your current location based on your IP address.
Response:
[
{
"city": "Madrid",
"cityLabel": "madrid",
"country": "507f1f77bcf86cd799439011",
"location": {
"type": "Point",
"coordinates": [-3.7038, 40.4168]
},
"population": 3223334
}
]GET /getCity
Search for cities by name, country, and/or population range.
Query Parameters:
city(string): City name (case-insensitive)country(string): Country name (case-insensitive)minPopulation(number): Minimum populationmaxPopulation(number): Maximum population
Example:
GET /getCity?city=madrid&country=spain
GET /getCity?minPopulation=1000000&maxPopulation=5000000
Response:
[
{
"city": "Madrid",
"cityLabel": "madrid",
"country": "507f1f77bcf86cd799439011",
"location": {
"type": "Point",
"coordinates": [-3.7038, 40.4168]
},
"population": 3223334
}
]- Bun installed
- MongoDB instance running
- Redis instance running (optional, for ratelimit)
- Clone the repository:
git clone https://github.com/txuli/finda.city.git
cd finda.city- Install dependencies:
bun install- Configure environment variables (create a
.envfile):
PORT=3000
MONGODB_URI=mongodb://localhost:27017/finda
REDIS_URL=redis://localhost:6379- Start the server:
bun run src/index.tsThe API will be running at http://localhost:3000
{
CountryLabel: string, // Lowercase country name
country: string, // Capitalized country name
CapitalLabel: string, // Capital city name
iso2: string, // ISO 3166-1 alpha-2 code
population: number, // Country population
lifeExpectancy: number, // Life expectancy in years
continent: string, // Continent name
lat: number, // Latitude
lon: number, // Longitude
fullData: boolean, // Data completeness flag
wikiId: string // Wikidata ID (e.g., "Q29")
}{
city: string, // City name
cityLabel: string, // Lowercase city name
country: ObjectId, // Reference to Country
location: {
type: "Point",
coordinates: [number, number] // [longitude, latitude]
},
population: number // City population
}