Article
NIK Generator ID - Generate Indonesian NIKs for Testing
NIK Generator ID is a JS/TS package for generating random or custom Indonesian identity numbers (NIK) for tests and mock data, built on real regional codes.
Overview
I got tired of hand-crafting fake Indonesian identity numbers (NIK) for test data, so I built NIK Generator ID, a lightweight JavaScript/TypeScript package that generates valid-looking Indonesian NIKs, either random or built to your spec.
If you’re working with mock user data for Indonesia, an e-KTP app, test automation, or anything that needs realistic-looking IDs, this saves a fair amount of typing.
What it does
NIK Generator ID produces random or customized Indonesian National Identity Numbers. It’s built on real regional data (provinces, cities, districts), so the NIKs it generates are structurally correct even though they’re not tied to actual people.
It’s not official, but the format matches what a real NIK looks like, which is exactly what you want for tests without touching real personal data.
Install
npm install nik-generator-id Then import it:
ES Modules
import { generateNik, getProvinces, getRegencies, getDistricts } from 'nik-generator-id'; CommonJS
const { generateNik, getProvinces, getRegencies, getDistricts } = require('nik-generator-id'); What it gives you
- Random NIKs: one function call returns a valid 16-digit NIK.
- Full customization: control gender, birthdate, and region.
- Real regional data: based on Indonesia’s actual administrative divisions.
- Correct format: 16 digits, structured the way a real NIK is.
- Small footprint: no dependencies beyond the regional data itself.
Quick examples
Generate a random NIK
const nik = generateNik();
console.log(nik); // e.g., 3273081505900001 Generate a NIK for a male
const maleNik = generateNik({ gender: 'male' });
console.log(maleNik); Generate a NIK for a female born January 15, 1990
const femaleNik = generateNik({
gender: 'female',
birthDate: new Date(1990, 0, 15)
});
console.log(femaleNik); Generate a NIK for a specific location
const specificNik = generateNik({
provinceCode: '32', // West Java
regencyCode: '73', // Bandung City
districtCode: '08' // Specific district
});
console.log(specificNik); Working with regional data
You can also pull region lists directly, useful for building location pickers or just poking around the dataset.
Get provinces
const provinces = getProvinces();
console.log(provinces);
// [{ code: '11', name: 'Aceh' }, ...] Get regencies in a province
const regencies = getRegencies('11'); // Aceh
console.log(regencies); Get districts in a regency
const districts = getDistricts('11', '01'); // Aceh Selatan
console.log(districts); How the NIK format works
Each NIK is 16 digits long, structured like this:
PPRRDDTTMMYYXXXX PP: province code (2 digits)RR: regency/city code (2 digits)DD: district code (2 digits)TT: day of birth (add 40 for female)MM: birth monthYY: last two digits of birth yearXXXX: random sequence
Example: 3273081505900001 decodes to West Java, Bandung City, district 08, born May 15, 1990, sequence 0001.
A few caveats
- Not for real-world use. This is strictly for testing and development.
- The regional codes are accurate, even though the generated NIKs aren’t tied to real people.
- Contributions welcome. Bugs, ideas, or feature requests can go through GitHub.
Why bother
- Saves time over hand-coding fake NIKs one at a time.
- Structurally correct, so it holds up in tests and demos.
- Customizable enough to match whatever scenario you’re testing.
- Open source under the MIT license.
Try it
npm install nik-generator-id Full docs and source are on GitHub.