{"id":16631,"library":"indian-cities-database","title":"Indian Cities Database","description":"The `indian-cities-database` package offers a structured dataset comprising Indian cities and their respective states, designed for integration into Node.js applications. It provides a static JavaScript array containing city-state objects, which can be directly consumed or used to populate a local MongoDB instance. The current and likely final stable version is 1.0.5, with its last known activity dating back to September 2016, indicating that the package is no longer actively maintained. A key feature is its ability to push this geographical data to MongoDB, complete with a predefined Mongoose schema for streamlined querying. This library simplifies the integration of Indian location data, providing a readily available dataset and tools for database persistence, bypassing the need for manual data sourcing and structuring.","status":"abandoned","version":"1.0.5","language":"javascript","source_language":"en","source_url":"https://github.com/thatisuday/indian-cities-database","tags":["javascript","database","cities","states","india"],"install":[{"cmd":"npm install indian-cities-database","lang":"bash","label":"npm"},{"cmd":"yarn add indian-cities-database","lang":"bash","label":"yarn"},{"cmd":"pnpm add indian-cities-database","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"Required if using `pushToDatabase` or `citySchema` functionality for MongoDB integration.","package":"mongoose","optional":true}],"imports":[{"note":"The `cities` array is a direct property of the main module export. The package is CommonJS only.","wrong":"import { cities } from 'indian-cities-database';","symbol":"cities","correct":"const { cities } = require('indian-cities-database');"},{"note":"The `pushToDatabase` function is a direct property of the main module export. The package is CommonJS only.","wrong":"import { pushToDatabase } from 'indian-cities-database';","symbol":"pushToDatabase","correct":"const { pushToDatabase } = require('indian-cities-database');"},{"note":"The `citySchema` (Mongoose schema) is a direct property of the main module export. The package is CommonJS only.","wrong":"import { citySchema } from 'indian-cities-database';","symbol":"citySchema","correct":"const { citySchema } = require('indian-cities-database');"}],"quickstart":{"code":"const indianCitiesDatabase = require('indian-cities-database');\n\n// Get the full list of cities and states\nconst cities = indianCitiesDatabase.cities;\n\nconsole.log(`Total cities found: ${cities.length}`);\nconsole.log('First 5 cities:');\ncities.slice(0, 5).forEach(city => {\n  console.log(`  - ${city.city}, ${city.state}`);\n});\n\n// Example of accessing the Mongoose schema (requires Mongoose to be installed separately)\n// Note: This won't run without 'mongoose' installed and a MongoDB connection.\n// try {\n//   const mongoose = require('mongoose');\n//   const citySchema = indianCitiesDatabase.citySchema;\n//   citySchema.set('collection', 'my_cities_collection');\n//   const MyCity = mongoose.model('MyCity', citySchema);\n//   console.log('Mongoose City Model created successfully (schema only).');\n// } catch (e) {\n//   console.warn('Mongoose or MongoDB not available, skipping schema example:', e.message);\n// }","lang":"javascript","description":"Demonstrates how to import the package and access the static `cities` array. Also hints at schema usage."},"warnings":[{"fix":"Ensure critical data is backed up or use this method only on non-production or new collections. Manually inspect the `populate.js` script in the package source for its exact behavior if concerned.","message":"The `pushToDatabase` method irrevocably removes the specified MongoDB collection (if it exists) before repopulating it with city data. This is a destructive operation and should be used with extreme caution.","severity":"breaking","affected_versions":">=1.0.0"},{"fix":"It is strongly recommended to run `pushToDatabase` as a one-off script (e.g., `node populate.js` as suggested in the README) during development or deployment, rather than embedding it directly into runtime application logic.","message":"Calling `pushToDatabase` within an API or frequently-executed code can lead to database connection collisions, as the method creates its own Mongoose connection. This can disrupt existing database connections in your application.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"Use `const packageName = require('indian-cities-database');` for all imports. In ESM projects, you might need a wrapper or dynamic import (`await import('indian-cities-database')`) if absolutely necessary, but it's not officially supported.","message":"This package is CommonJS-only and does not provide ESM exports. Direct `import` statements will fail in pure ESM Node.js environments.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"Consider validating the data against current Indian city/state lists. For production applications requiring up-to-date geographical data or active maintenance, explore alternative actively maintained libraries or datasets.","message":"The package has not received updates since September 2016 (version 1.0.5). The city data might be outdated, and there will be no future bug fixes, security updates, or feature enhancements.","severity":"deprecated","affected_versions":">=1.0.5"}],"env_vars":null,"last_verified":"2026-04-22T00:00:00.000Z","next_check":"2026-07-21T00:00:00.000Z","problems":[{"fix":"Ensure you are using CommonJS `const { cities } = require('indian-cities-database');` as the library is CJS-only. If `cities` is undefined after `require`, verify the package installation and the correct property name.","cause":"Attempting to use ES Modules `import { cities } from 'indian-cities-database';` in a CommonJS context or vice-versa, or incorrectly accessing a non-existent export.","error":"TypeError: Cannot destructure property 'cities' of 'indianCitiesDatabase' as it is undefined."},{"fix":"The `pushToDatabase` function has optional arguments: `databaseName`, `collectionName`, and `callback`. Ensure that if you are providing a database name, it's a valid string. If Mongoose is trying to connect without a URI, it likely defaults to `mongodb://localhost:27017/` which might require a running local MongoDB instance. Check the underlying `populate.js` file for default connection logic.","cause":"When attempting to use `pushToDatabase`, Mongoose is trying to connect to a database but the connection URI (or other connection options) is not being provided or is incorrect. This function uses its own internal Mongoose instance.","error":"MongooseError: The `uri` parameter to `openUri()` must be a string, got 'undefined'."}],"ecosystem":"npm"}