Registry / database / indian-cities-database

indian-cities-database

JSON →
library1.0.5jsnpmunverified

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.

npm install indian-cities-database
INSTALL
IMPORT
SIG · INDIAN-CITIES-DATA
I
indian-cities-database
databasejavascriptv1.0.5
Install
Import
Disk
Pass rate
0/ 6
Env Coverage0 / 6
glibc
1822
musl
1822
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
node 18226 runs
build_error
glibc
node 18226 runs
build_error
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

cities
const { cities } = require('indian-cities-database');
import { cities } from 'indian-cities-database';
The `cities` array is a direct property of the main module export. The package is CommonJS only.
pushToDatabase
const { pushToDatabase } = require('indian-cities-database');
import { pushToDatabase } from 'indian-cities-database';
The `pushToDatabase` function is a direct property of the main module export. The package is CommonJS only.
citySchema
const { citySchema } = require('indian-cities-database');
import { citySchema } from 'indian-cities-database';
The `citySchema` (Mongoose schema) is a direct property of the main module export. The package is CommonJS only.

Demonstrates how to import the package and access the static `cities` array. Also hints at schema usage.

const indianCitiesDatabase = require('indian-cities-database'); // Get the full list of cities and states const cities = indianCitiesDatabase.cities; console.log(`Total cities found: ${cities.length}`); console.log('First 5 cities:'); cities.slice(0, 5).forEach(city => { console.log(` - ${city.city}, ${city.state}`); }); // Example of accessing the Mongoose schema (requires Mongoose to be installed separately) // Note: This won't run without 'mongoose' installed and a MongoDB connection. // try { // const mongoose = require('mongoose'); // const citySchema = indianCitiesDatabase.citySchema; // citySchema.set('collection', 'my_cities_collection'); // const MyCity = mongoose.model('MyCity', citySchema); // console.log('Mongoose City Model created successfully (schema only).'); // } catch (e) { // console.warn('Mongoose or MongoDB not available, skipping schema example:', e.message); // }
Debug
Known issues
breakingThe `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.
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.
affects: >=1.0.0
gotchaCalling `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.
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.
affects: >=1.0.0
gotchaThis package is CommonJS-only and does not provide ESM exports. Direct `import` statements will fail in pure ESM Node.js environments.
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.
affects: >=1.0.0
deprecatedThe 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.
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.
affects: >=1.0.5
Errors
Common errors & fixes
TypeError: Cannot destructure property 'cities' of 'indianCitiesDatabase' as it is undefined.
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.
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.
MongooseError: The `uri` parameter to `openUri()` must be a string, got 'undefined'.
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.
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.
Upgrade
Version history
1.0.5latest on npm
Audit
Dependencies
mongooseoptionalRequired if using `pushToDatabase` or `citySchema` functionality for MongoDB integration.
Agent activity
8 hits · last 30 days
node
8
Resources