Skip to content

Instantly share code, notes, and snippets.

@jyotendra
Created July 23, 2018 13:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jyotendra/50292ccc7f3a103b087ca1a3fc2754b8 to your computer and use it in GitHub Desktop.
Save jyotendra/50292ccc7f3a103b087ca1a3fc2754b8 to your computer and use it in GitHub Desktop.
This gist shows how to import json asynchronously in nodejs
[
[1, "Afghanistan", "AF", 93, "0000-00-00 00:00:00", "0000-00-00 00:00:00"],
[2, "Albania", "AL", 355, "0000-00-00 00:00:00", "0000-00-00 00:00:00"],
[3, "Algeria", "DZ", 213, "0000-00-00 00:00:00", "0000-00-00 00:00:00"],
[4, "American Samoa", "AS", 1684, "0000-00-00 00:00:00", "0000-00-00 00:00:00"],
[5, "Andorra", "AD", 376, "0000-00-00 00:00:00", "0000-00-00 00:00:00"],
[6, "Angola", "AO", 244, "0000-00-00 00:00:00", "0000-00-00 00:00:00"],
[7, "Anguilla", "AI", 1264, "0000-00-00 00:00:00", "0000-00-00 00:00:00"],
[8, "Antarctica", "AQ", 0, "0000-00-00 00:00:00", "0000-00-00 00:00:00"],
[9, "Antigua And Barbuda", "AG", 1268, "0000-00-00 00:00:00", "0000-00-00 00:00:00"],
[10, "Argentina", "AR", 54, "0000-00-00 00:00:00", "0000-00-00 00:00:00"],
[11, "Armenia", "AM", 374, "0000-00-00 00:00:00", "0000-00-00 00:00:00"],
[12, "Aruba", "AW", 297, "0000-00-00 00:00:00", "0000-00-00 00:00:00"],
[13, "Australia", "AU", 61, "0000-00-00 00:00:00", "0000-00-00 00:00:00"],
[14, "Austria", "AT", 43, "0000-00-00 00:00:00", "0000-00-00 00:00:00"],
[15, "Azerbaijan", "AZ", 994, "0000-00-00 00:00:00", "0000-00-00 00:00:00"],
[16, "Bahamas The", "BS", 1242, "0000-00-00 00:00:00", "0000-00-00 00:00:00"],
[17, "Bahrain", "BH", 973, "0000-00-00 00:00:00", "0000-00-00 00:00:00"],
[18, "Bangladesh", "BD", 880, "0000-00-00 00:00:00", "0000-00-00 00:00:00"],
[19, "Barbados", "BB", 1246, "0000-00-00 00:00:00", "0000-00-00 00:00:00"],
[20, "Belarus", "BY", 375, "0000-00-00 00:00:00", "0000-00-00 00:00:00"],
[21, "Belgium", "BE", 32, "0000-00-00 00:00:00", "0000-00-00 00:00:00"],
[22, "Belize", "BZ", 501, "0000-00-00 00:00:00", "0000-00-00 00:00:00"],
[23, "Benin", "BJ", 229, "0000-00-00 00:00:00", "0000-00-00 00:00:00"],
[24, "Bermuda", "BM", 1441, "0000-00-00 00:00:00", "0000-00-00 00:00:00"],
[25, "Bhutan", "BT", 975, "0000-00-00 00:00:00", "0000-00-00 00:00:00"],
[26, "Bolivia", "BO", 591, "0000-00-00 00:00:00", "0000-00-00 00:00:00"],
[27, "Bosnia and Herzegovina", "BA", 387, "0000-00-00 00:00:00", "0000-00-00 00:00:00"],
[28, "Botswana", "BW", 267, "0000-00-00 00:00:00", "0000-00-00 00:00:00"],
[29, "Bouvet Island", "BV", 0, "0000-00-00 00:00:00", "0000-00-00 00:00:00"],
[30, "Brazil", "BR", 55, "0000-00-00 00:00:00", "0000-00-00 00:00:00"],
[31, "British Indian Ocean Territory", "IO", 246, "0000-00-00 00:00:00", "0000-00-00 00:00:00"],
[32, "Brunei", "BN", 673, "0000-00-00 00:00:00", "0000-00-00 00:00:00"],
[33, "Bulgaria", "BG", 359, "0000-00-00 00:00:00", "0000-00-00 00:00:00"],
[34, "Burkina Faso", "BF", 226, "0000-00-00 00:00:00", "0000-00-00 00:00:00"],
[35, "Burundi", "BI", 257, "0000-00-00 00:00:00", "0000-00-00 00:00:00"],
[36, "Cambodia", "KH", 855, "0000-00-00 00:00:00", "0000-00-00 00:00:00"],
[37, "Cameroon", "CM", 237, "0000-00-00 00:00:00", "0000-00-00 00:00:00"],
[38, "Canada", "CA", 1, "0000-00-00 00:00:00", "0000-00-00 00:00:00"],
[39, "Cape Verde", "CV", 238, "0000-00-00 00:00:00", "0000-00-00 00:00:00"],
[40, "Cayman Islands", "KY", 1345, "0000-00-00 00:00:00", "0000-00-00 00:00:00"],
[41, "Central African Republic", "CF", 236, "0000-00-00 00:00:00", "0000-00-00 00:00:00"],
[42, "Chad", "TD", 235, "0000-00-00 00:00:00", "0000-00-00 00:00:00"],
[43, "Chile", "CL", 56, "0000-00-00 00:00:00", "0000-00-00 00:00:00"],
[44, "China", "CN", 86, "0000-00-00 00:00:00", "0000-00-00 00:00:00"],
[45, "Christmas Island", "CX", 61, "0000-00-00 00:00:00", "0000-00-00 00:00:00"],
[46, "Cocos [Keeling] Islands", "CC", 672, "0000-00-00 00:00:00", "0000-00-00 00:00:00"],
[47, "Colombia", "CO", 57, "0000-00-00 00:00:00", "0000-00-00 00:00:00"],
[48, "Comoros", "KM", 269, "0000-00-00 00:00:00", "0000-00-00 00:00:00"],
[49, "Republic Of The Congo", "CG", 242, "0000-00-00 00:00:00", "0000-00-00 00:00:00"],
[50, "Democratic Republic Of The Congo", "CD", 242, "0000-00-00 00:00:00", "0000-00-00 00:00:00"],
[51, "Cook Islands", "CK", 682, "0000-00-00 00:00:00", "0000-00-00 00:00:00"],
[52, "Costa Rica", "CR", 506, "0000-00-00 00:00:00", "0000-00-00 00:00:00"],
[53, "Cote D'Ivoire [Ivory Coast]", "CI", 225, "0000-00-00 00:00:00", "0000-00-00 00:00:00"],
[54, "Croatia [Hrvatska]", "HR", 385, "0000-00-00 00:00:00", "0000-00-00 00:00:00"],
[55, "Cuba", "CU", 53, "0000-00-00 00:00:00", "0000-00-00 00:00:00"],
[56, "Cyprus", "CY", 357, "0000-00-00 00:00:00", "0000-00-00 00:00:00"],
[57, "Czech Republic", "CZ", 420, "0000-00-00 00:00:00", "0000-00-00 00:00:00"],
[58, "Denmark", "DK", 45, "0000-00-00 00:00:00", "0000-00-00 00:00:00"],
[59, "Djibouti", "DJ", 253, "0000-00-00 00:00:00", "0000-00-00 00:00:00"],
[60, "Dominica", "DM", 1767, "0000-00-00 00:00:00", "0000-00-00 00:00:00"],
[61, "Dominican Republic", "DO", 1809, "0000-00-00 00:00:00", "0000-00-00 00:00:00"],
[62, "East Timor", "TP", 670, "0000-00-00 00:00:00", "0000-00-00 00:00:00"],
[63, "Ecuador", "EC", 593, "0000-00-00 00:00:00", "0000-00-00 00:00:00"],
[64, "Egypt", "EG", 20, "0000-00-00 00:00:00", "0000-00-00 00:00:00"],
[65, "El Salvador", "SV", 503, "0000-00-00 00:00:00", "0000-00-00 00:00:00"],
[66, "Equatorial Guinea", "GQ", 240, "0000-00-00 00:00:00", "0000-00-00 00:00:00"],
[67, "Eritrea", "ER", 291, "0000-00-00 00:00:00", "0000-00-00 00:00:00"],
[68, "Estonia", "EE", 372, "0000-00-00 00:00:00", "0000-00-00 00:00:00"],
[69, "Ethiopia", "ET", 251, "0000-00-00 00:00:00", "0000-00-00 00:00:00"],
[70, "External Territories of Australia", "XA", 61, "0000-00-00 00:00:00", "0000-00-00 00:00:00"],
[71, "Falkland Islands", "FK", 500, "0000-00-00 00:00:00", "0000-00-00 00:00:00"],
[72, "Faroe Islands", "FO", 298, "0000-00-00 00:00:00", "0000-00-00 00:00:00"],
[73, "Fiji Islands", "FJ", 679, "0000-00-00 00:00:00", "0000-00-00 00:00:00"],
[74, "Finland", "FI", 358, "0000-00-00 00:00:00", "0000-00-00 00:00:00"],
[75, "France", "FR", 33, "0000-00-00 00:00:00", "0000-00-00 00:00:00"],
[76, "French Guiana", "GF", 594, "0000-00-00 00:00:00", "0000-00-00 00:00:00"],
[77, "French Polynesia", "PF", 689, "0000-00-00 00:00:00", "0000-00-00 00:00:00"],
[78, "French Southern Territories", "TF", 0, "0000-00-00 00:00:00", "0000-00-00 00:00:00"],
[79, "Gabon", "GA", 241, "0000-00-00 00:00:00", "0000-00-00 00:00:00"],
[80, "Gambia The", "GM", 220, "0000-00-00 00:00:00", "0000-00-00 00:00:00"],
[81, "Georgia", "GE", 995, "0000-00-00 00:00:00", "0000-00-00 00:00:00"],
[82, "Germany", "DE", 49, "0000-00-00 00:00:00", "0000-00-00 00:00:00"],
[83, "Ghana", "GH", 233, "0000-00-00 00:00:00", "0000-00-00 00:00:00"],
[84, "Gibraltar", "GI", 350, "0000-00-00 00:00:00", "0000-00-00 00:00:00"],
[85, "Greece", "GR", 30, "0000-00-00 00:00:00", "0000-00-00 00:00:00"],
[86, "Greenland", "GL", 299, "0000-00-00 00:00:00", "0000-00-00 00:00:00"],
[87, "Grenada", "GD", 1473, "0000-00-00 00:00:00", "0000-00-00 00:00:00"],
[88, "Guadeloupe", "GP", 590, "0000-00-00 00:00:00", "0000-00-00 00:00:00"],
[89, "Guam", "GU", 1671, "0000-00-00 00:00:00", "0000-00-00 00:00:00"],
[90, "Guatemala", "GT", 502, "0000-00-00 00:00:00", "0000-00-00 00:00:00"],
[91, "Guernsey and Alderney", "XU", 44, "0000-00-00 00:00:00", "0000-00-00 00:00:00"],
[92, "Guinea", "GN", 224, "0000-00-00 00:00:00", "0000-00-00 00:00:00"],
[93, "Guinea-Bissau", "GW", 245, "0000-00-00 00:00:00", "0000-00-00 00:00:00"],
[94, "Guyana", "GY", 592, "0000-00-00 00:00:00", "0000-00-00 00:00:00"],
[95, "Haiti", "HT", 509, "0000-00-00 00:00:00", "0000-00-00 00:00:00"],
[96, "Heard and McDonald Islands", "HM", 0, "0000-00-00 00:00:00", "0000-00-00 00:00:00"],
[97, "Honduras", "HN", 504, "0000-00-00 00:00:00", "0000-00-00 00:00:00"],
[98, "Hong Kong S.A.R.", "HK", 852, "0000-00-00 00:00:00", "0000-00-00 00:00:00"],
[99, "Hungary", "HU", 36, "0000-00-00 00:00:00", "0000-00-00 00:00:00"],
[100, "Iceland", "IS", 354, "0000-00-00 00:00:00", "0000-00-00 00:00:00"],
[101, "India", "IN", 91, "0000-00-00 00:00:00", "0000-00-00 00:00:00"],
[102, "Indonesia", "ID", 62, "0000-00-00 00:00:00", "0000-00-00 00:00:00"],
[103, "Iran", "IR", 98, "0000-00-00 00:00:00", "0000-00-00 00:00:00"],
[104, "Iraq", "IQ", 964, "0000-00-00 00:00:00", "0000-00-00 00:00:00"],
[105, "Ireland", "IE", 353, "0000-00-00 00:00:00", "0000-00-00 00:00:00"],
[106, "Israel", "IL", 972, "0000-00-00 00:00:00", "0000-00-00 00:00:00"],
[107, "Italy", "IT", 39, "0000-00-00 00:00:00", "0000-00-00 00:00:00"],
[108, "Jamaica", "JM", 1876, "0000-00-00 00:00:00", "0000-00-00 00:00:00"],
[109, "Japan", "JP", 81, "0000-00-00 00:00:00", "0000-00-00 00:00:00"],
[110, "Jersey", "XJ", 44, "0000-00-00 00:00:00", "0000-00-00 00:00:00"],
[111, "Jordan", "JO", 962, "0000-00-00 00:00:00", "0000-00-00 00:00:00"],
[112, "Kazakhstan", "KZ", 7, "0000-00-00 00:00:00", "0000-00-00 00:00:00"],
[113, "Kenya", "KE", 254, "0000-00-00 00:00:00", "0000-00-00 00:00:00"],
[114, "Kiribati", "KI", 686, "0000-00-00 00:00:00", "0000-00-00 00:00:00"],
[115, "Korea North", "KP", 850, "0000-00-00 00:00:00", "0000-00-00 00:00:00"],
[116, "Korea South", "KR", 82, "0000-00-00 00:00:00", "0000-00-00 00:00:00"],
[117, "Kuwait", "KW", 965, "0000-00-00 00:00:00", "0000-00-00 00:00:00"],
[118, "Kyrgyzstan", "KG", 996, "0000-00-00 00:00:00", "0000-00-00 00:00:00"],
[119, "Laos", "LA", 856, "0000-00-00 00:00:00", "0000-00-00 00:00:00"],
[120, "Latvia", "LV", 371, "0000-00-00 00:00:00", "0000-00-00 00:00:00"],
[121, "Lebanon", "LB", 961, "0000-00-00 00:00:00", "0000-00-00 00:00:00"],
[122, "Lesotho", "LS", 266, "0000-00-00 00:00:00", "0000-00-00 00:00:00"],
[123, "Liberia", "LR", 231, "0000-00-00 00:00:00", "0000-00-00 00:00:00"],
[124, "Libya", "LY", 218, "0000-00-00 00:00:00", "0000-00-00 00:00:00"],
[125, "Liechtenstein", "LI", 423, "0000-00-00 00:00:00", "0000-00-00 00:00:00"],
[126, "Lithuania", "LT", 370, "0000-00-00 00:00:00", "0000-00-00 00:00:00"],
[127, "Luxembourg", "LU", 352, "0000-00-00 00:00:00", "0000-00-00 00:00:00"],
[128, "Macau S.A.R.", "MO", 853, "0000-00-00 00:00:00", "0000-00-00 00:00:00"],
[129, "Macedonia", "MK", 389, "0000-00-00 00:00:00", "0000-00-00 00:00:00"],
[130, "Madagascar", "MG", 261, "0000-00-00 00:00:00", "0000-00-00 00:00:00"],
[131, "Malawi", "MW", 265, "0000-00-00 00:00:00", "0000-00-00 00:00:00"],
[132, "Malaysia", "MY", 60, "0000-00-00 00:00:00", "0000-00-00 00:00:00"],
[133, "Maldives", "MV", 960, "0000-00-00 00:00:00", "0000-00-00 00:00:00"],
[134, "Mali", "ML", 223, "0000-00-00 00:00:00", "0000-00-00 00:00:00"],
[135, "Malta", "MT", 356, "0000-00-00 00:00:00", "0000-00-00 00:00:00"],
[136, "Man [Isle of]", "XM", 44, "0000-00-00 00:00:00", "0000-00-00 00:00:00"],
[137, "Marshall Islands", "MH", 692, "0000-00-00 00:00:00", "0000-00-00 00:00:00"],
[138, "Martinique", "MQ", 596, "0000-00-00 00:00:00", "0000-00-00 00:00:00"],
[139, "Mauritania", "MR", 222, "0000-00-00 00:00:00", "0000-00-00 00:00:00"],
[140, "Mauritius", "MU", 230, "0000-00-00 00:00:00", "0000-00-00 00:00:00"],
[141, "Mayotte", "YT", 269, "0000-00-00 00:00:00", "0000-00-00 00:00:00"],
[142, "Mexico", "MX", 52, "0000-00-00 00:00:00", "0000-00-00 00:00:00"],
[143, "Micronesia", "FM", 691, "0000-00-00 00:00:00", "0000-00-00 00:00:00"],
[144, "Moldova", "MD", 373, "0000-00-00 00:00:00", "0000-00-00 00:00:00"],
[145, "Monaco", "MC", 377, "0000-00-00 00:00:00", "0000-00-00 00:00:00"],
[146, "Mongolia", "MN", 976, "0000-00-00 00:00:00", "0000-00-00 00:00:00"],
[147, "Montserrat", "MS", 1664, "0000-00-00 00:00:00", "0000-00-00 00:00:00"],
[148, "Morocco", "MA", 212, "0000-00-00 00:00:00", "0000-00-00 00:00:00"],
[149, "Mozambique", "MZ", 258, "0000-00-00 00:00:00", "0000-00-00 00:00:00"],
[150, "Myanmar", "MM", 95, "0000-00-00 00:00:00", "0000-00-00 00:00:00"],
[151, "Namibia", "NA", 264, "0000-00-00 00:00:00", "0000-00-00 00:00:00"],
[152, "Nauru", "NR", 674, "0000-00-00 00:00:00", "0000-00-00 00:00:00"],
[153, "Nepal", "NP", 977, "0000-00-00 00:00:00", "0000-00-00 00:00:00"],
[154, "Netherlands Antilles", "AN", 599, "0000-00-00 00:00:00", "0000-00-00 00:00:00"],
[155, "Netherlands The", "NL", 31, "0000-00-00 00:00:00", "0000-00-00 00:00:00"],
[156, "New Caledonia", "NC", 687, "0000-00-00 00:00:00", "0000-00-00 00:00:00"],
[157, "New Zealand", "NZ", 64, "0000-00-00 00:00:00", "0000-00-00 00:00:00"],
[158, "Nicaragua", "NI", 505, "0000-00-00 00:00:00", "0000-00-00 00:00:00"],
[159, "Niger", "NE", 227, "0000-00-00 00:00:00", "0000-00-00 00:00:00"],
[160, "Nigeria", "NG", 234, "0000-00-00 00:00:00", "0000-00-00 00:00:00"],
[161, "Niue", "NU", 683, "0000-00-00 00:00:00", "0000-00-00 00:00:00"],
[162, "Norfolk Island", "NF", 672, "0000-00-00 00:00:00", "0000-00-00 00:00:00"],
[163, "Northern Mariana Islands", "MP", 1670, "0000-00-00 00:00:00", "0000-00-00 00:00:00"],
[164, "Norway", "NO", 47, "0000-00-00 00:00:00", "0000-00-00 00:00:00"],
[165, "Oman", "OM", 968, "0000-00-00 00:00:00", "0000-00-00 00:00:00"],
[166, "Pakistan", "PK", 92, "0000-00-00 00:00:00", "0000-00-00 00:00:00"],
[167, "Palau", "PW", 680, "0000-00-00 00:00:00", "0000-00-00 00:00:00"],
[168, "Palestinian Territory Occupied", "PS", 970, "0000-00-00 00:00:00", "0000-00-00 00:00:00"],
[169, "Panama", "PA", 507, "0000-00-00 00:00:00", "0000-00-00 00:00:00"],
[170, "Papua new Guinea", "PG", 675, "0000-00-00 00:00:00", "0000-00-00 00:00:00"],
[171, "Paraguay", "PY", 595, "0000-00-00 00:00:00", "0000-00-00 00:00:00"],
[172, "Peru", "PE", 51, "0000-00-00 00:00:00", "0000-00-00 00:00:00"],
[173, "Philippines", "PH", 63, "0000-00-00 00:00:00", "0000-00-00 00:00:00"],
[174, "Pitcairn Island", "PN", 0, "0000-00-00 00:00:00", "0000-00-00 00:00:00"],
[175, "Poland", "PL", 48, "0000-00-00 00:00:00", "0000-00-00 00:00:00"],
[176, "Portugal", "PT", 351, "0000-00-00 00:00:00", "0000-00-00 00:00:00"],
[177, "Puerto Rico", "PR", 1787, "0000-00-00 00:00:00", "0000-00-00 00:00:00"],
[178, "Qatar", "QA", 974, "0000-00-00 00:00:00", "0000-00-00 00:00:00"],
[179, "Reunion", "RE", 262, "0000-00-00 00:00:00", "0000-00-00 00:00:00"],
[180, "Romania", "RO", 40, "0000-00-00 00:00:00", "0000-00-00 00:00:00"],
[181, "Russia", "RU", 70, "0000-00-00 00:00:00", "0000-00-00 00:00:00"],
[182, "Rwanda", "RW", 250, "0000-00-00 00:00:00", "0000-00-00 00:00:00"],
[183, "Saint Helena", "SH", 290, "0000-00-00 00:00:00", "0000-00-00 00:00:00"],
[184, "Saint Kitts And Nevis", "KN", 1869, "0000-00-00 00:00:00", "0000-00-00 00:00:00"],
[185, "Saint Lucia", "LC", 1758, "0000-00-00 00:00:00", "0000-00-00 00:00:00"],
[186, "Saint Pierre and Miquelon", "PM", 508, "0000-00-00 00:00:00", "0000-00-00 00:00:00"],
[187, "Saint Vincent And The Grenadines", "VC", 1784, "0000-00-00 00:00:00", "0000-00-00 00:00:00"],
[188, "Samoa", "WS", 684, "0000-00-00 00:00:00", "0000-00-00 00:00:00"],
[189, "San Marino", "SM", 378, "0000-00-00 00:00:00", "0000-00-00 00:00:00"],
[190, "Sao Tome and Principe", "ST", 239, "0000-00-00 00:00:00", "0000-00-00 00:00:00"],
[191, "Saudi Arabia", "SA", 966, "0000-00-00 00:00:00", "0000-00-00 00:00:00"],
[192, "Senegal", "SN", 221, "0000-00-00 00:00:00", "0000-00-00 00:00:00"],
[193, "Serbia", "RS", 381, "0000-00-00 00:00:00", "0000-00-00 00:00:00"],
[194, "Seychelles", "SC", 248, "0000-00-00 00:00:00", "0000-00-00 00:00:00"],
[195, "Sierra Leone", "SL", 232, "0000-00-00 00:00:00", "0000-00-00 00:00:00"],
[196, "Singapore", "SG", 65, "0000-00-00 00:00:00", "0000-00-00 00:00:00"],
[197, "Slovakia", "SK", 421, "0000-00-00 00:00:00", "0000-00-00 00:00:00"],
[198, "Slovenia", "SI", 386, "0000-00-00 00:00:00", "0000-00-00 00:00:00"],
[199, "Smaller Territories of the UK", "XG", 44, "0000-00-00 00:00:00", "0000-00-00 00:00:00"],
[200, "Solomon Islands", "SB", 677, "0000-00-00 00:00:00", "0000-00-00 00:00:00"],
[201, "Somalia", "SO", 252, "0000-00-00 00:00:00", "0000-00-00 00:00:00"],
[202, "South Africa", "ZA", 27, "0000-00-00 00:00:00", "0000-00-00 00:00:00"],
[203, "South Georgia", "GS", 0, "0000-00-00 00:00:00", "0000-00-00 00:00:00"],
[204, "South Sudan", "SS", 211, "0000-00-00 00:00:00", "0000-00-00 00:00:00"],
[205, "Spain", "ES", 34, "0000-00-00 00:00:00", "0000-00-00 00:00:00"],
[206, "Sri Lanka", "LK", 94, "0000-00-00 00:00:00", "0000-00-00 00:00:00"],
[207, "Sudan", "SD", 249, "0000-00-00 00:00:00", "0000-00-00 00:00:00"],
[208, "Suriname", "SR", 597, "0000-00-00 00:00:00", "0000-00-00 00:00:00"],
[209, "Svalbard And Jan Mayen Islands", "SJ", 47, "0000-00-00 00:00:00", "0000-00-00 00:00:00"],
[210, "Swaziland", "SZ", 268, "0000-00-00 00:00:00", "0000-00-00 00:00:00"],
[211, "Sweden", "SE", 46, "0000-00-00 00:00:00", "0000-00-00 00:00:00"],
[212, "Switzerland", "CH", 41, "0000-00-00 00:00:00", "0000-00-00 00:00:00"],
[213, "Syria", "SY", 963, "0000-00-00 00:00:00", "0000-00-00 00:00:00"],
[214, "Taiwan", "TW", 886, "0000-00-00 00:00:00", "0000-00-00 00:00:00"],
[215, "Tajikistan", "TJ", 992, "0000-00-00 00:00:00", "0000-00-00 00:00:00"],
[216, "Tanzania", "TZ", 255, "0000-00-00 00:00:00", "0000-00-00 00:00:00"],
[217, "Thailand", "TH", 66, "0000-00-00 00:00:00", "0000-00-00 00:00:00"],
[218, "Togo", "TG", 228, "0000-00-00 00:00:00", "0000-00-00 00:00:00"],
[219, "Tokelau", "TK", 690, "0000-00-00 00:00:00", "0000-00-00 00:00:00"],
[220, "Tonga", "TO", 676, "0000-00-00 00:00:00", "0000-00-00 00:00:00"],
[221, "Trinidad And Tobago", "TT", 1868, "0000-00-00 00:00:00", "0000-00-00 00:00:00"],
[222, "Tunisia", "TN", 216, "0000-00-00 00:00:00", "0000-00-00 00:00:00"],
[223, "Turkey", "TR", 90, "0000-00-00 00:00:00", "0000-00-00 00:00:00"],
[224, "Turkmenistan", "TM", 7370, "0000-00-00 00:00:00", "0000-00-00 00:00:00"],
[225, "Turks And Caicos Islands", "TC", 1649, "0000-00-00 00:00:00", "0000-00-00 00:00:00"],
[226, "Tuvalu", "TV", 688, "0000-00-00 00:00:00", "0000-00-00 00:00:00"],
[227, "Uganda", "UG", 256, "0000-00-00 00:00:00", "0000-00-00 00:00:00"],
[228, "Ukraine", "UA", 380, "0000-00-00 00:00:00", "0000-00-00 00:00:00"],
[229, "United Arab Emirates", "AE", 971, "0000-00-00 00:00:00", "0000-00-00 00:00:00"],
[230, "United Kingdom", "GB", 44, "0000-00-00 00:00:00", "0000-00-00 00:00:00"],
[231, "United States", "US", 1, "0000-00-00 00:00:00", "0000-00-00 00:00:00"],
[232, "United States Minor Outlying Islands", "UM", 1, "0000-00-00 00:00:00", "0000-00-00 00:00:00"],
[233, "Uruguay", "UY", 598, "0000-00-00 00:00:00", "0000-00-00 00:00:00"],
[234, "Uzbekistan", "UZ", 998, "0000-00-00 00:00:00", "0000-00-00 00:00:00"],
[235, "Vanuatu", "VU", 678, "0000-00-00 00:00:00", "0000-00-00 00:00:00"],
[236, "Vatican City State [Holy See]", "VA", 39, "0000-00-00 00:00:00", "0000-00-00 00:00:00"],
[237, "Venezuela", "VE", 58, "0000-00-00 00:00:00", "0000-00-00 00:00:00"],
[238, "Vietnam", "VN", 84, "0000-00-00 00:00:00", "0000-00-00 00:00:00"],
[239, "Virgin Islands [British]", "VG", 1284, "0000-00-00 00:00:00", "0000-00-00 00:00:00"],
[240, "Virgin Islands [US]", "VI", 1340, "0000-00-00 00:00:00", "0000-00-00 00:00:00"],
[241, "Wallis And Futuna Islands", "WF", 681, "0000-00-00 00:00:00", "0000-00-00 00:00:00"],
[242, "Western Sahara", "EH", 212, "0000-00-00 00:00:00", "0000-00-00 00:00:00"],
[243, "Yemen", "YE", 967, "0000-00-00 00:00:00", "0000-00-00 00:00:00"],
[244, "Yugoslavia", "YU", 38, "0000-00-00 00:00:00", "0000-00-00 00:00:00"],
[245, "Zambia", "ZM", 260, "0000-00-00 00:00:00", "0000-00-00 00:00:00"],
[246, "Zimbabwe", "ZW", 263, "0000-00-00 00:00:00", "0000-00-00 00:00:00"]
]
import Promise from "bluebird";
import _ from "lodash";
import { resolve } from "path";
const fs = Promise.promisifyAll(require("fs"));
const countriesFile = resolve(__dirname, "../../config/countries.json");
// This function creates chunk of huge json data loaded asynchronously and inserts them to db in batch of 50
// If all the elements are tried to insert at once then resourceTimeOut was showing up from sequelize.
export async function seedCountries() {
try {
const countryCount = await db.countries.count();
if (countryCount <= 0) {
let countries = await fs.readFileAsync(countriesFile, "utf8");
countries = JSON.parse(countries);
countries = _.chunk(countries, 50);
for (let i = 0; i < countries.length; i++) {
const countryPromise = countries[i].map(country => {
// console.log(state);
return db.countries.create({
id: country[0],
name: country[1],
sortname: country[2],
phonecode: country[3]
});
});
// break;
await Promise.all(countryPromise);
}
}
} catch (err) {
logger.error("Error while seeding countries", err);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment