1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 1710 1711 1712 1713 1714 1715 1716 1717 1718 1719 1720 1721 1722 1723 1724 1725 1726 1727 1728 1729 1730 1731 1732 1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 1743 1744 1745 1746 1747 1748 1749 1750 1751 1752 1753 1754 1755 1756 1757 1758 1759 1760 1761 1762 1763 1764 1765 1766 1767 1768 1769 1770 1771 1772 1773 1774 1775 1776 1777 1778 1779 1780 1781 1782 1783 1784 1785 1786 1787 1788 1789 1790 1791 1792 1793 1794 1795 1796 1797 1798 1799 1800 1801 1802 1803 1804 1805 1806 1807 1808 1809 1810 1811 1812 1813 1814 1815 1816 1817 1818 1819 1820 1821 1822 1823 1824 1825 1826 1827 1828 1829 1830 1831 1832 1833 1834 1835 1836 1837 1838 1839 1840 1841 1842 1843 1844 1845 1846 1847 1848 1849 1850 1851 1852 1853 1854 1855 1856 1857 1858 1859 1860 1861 1862 1863 1864 1865 1866 1867 1868 1869 1870 1871 1872 1873 1874 1875 1876 1877 1878 1879 1880 1881 1882 1883 1884 1885 1886 1887 1888 1889 1890 1891 1892 1893 1894 1895 1896 1897 1898 1899 1900 1901 1902 1903 1904 1905 1906 1907 1908 1909 1910 1911 1912 1913 1914 1915 1916 1917 1918 1919 1920 1921 1922 1923 1924 1925 1926 1927 1928 1929 1930 1931 1932 1933 1934 1935 1936 1937 1938 1939 1940 1941 1942 1943 1944 1945 1946 1947 1948 1949 1950 1951 1952 1953 1954 1955 1956 1957 1958 1959 1960 1961 1962 1963 1964 1965 1966 1967 1968 1969 1970 1971 1972 1973 1974 1975 1976 1977 1978 1979 1980 1981 1982 1983 1984 1985 1986 1987 1988 1989 1990 1991 1992 1993 1994 1995 1996 1997 1998 1999 2000 2001 2002 2003 2004 2005 2006 2007 2008 2009 2010 2011 2012 2013 2014 2015 2016 2017 2018 2019 2020 2021 2022 2023 2024 2025 2026 2027 2028 2029 2030 2031 2032 2033 2034 2035 2036 2037 2038 2039 2040 2041 2042 2043 2044 2045 2046 2047 2048 2049 2050 2051 2052 2053 2054 2055 2056 2057 2058 2059 2060 2061 2062 2063 2064 2065 2066 2067 2068 2069 2070 2071 2072 2073 2074 2075 2076 2077 2078 2079 2080 2081 2082 2083 2084 2085 2086 2087 2088 2089 2090 2091 2092 2093 2094 2095 2096 2097 2098 2099 2100 2101 2102 2103 2104 2105 2106 2107 2108 2109 2110 2111 2112 2113 2114 2115 2116 2117 2118 2119 2120 2121 2122 2123 2124 2125 2126 2127 2128 2129 2130 2131 2132 2133 2134 2135 2136 2137 2138 2139 2140 2141 2142 2143 2144 2145 2146 2147 2148 2149 2150 2151 2152 2153 2154 2155 2156 2157 2158 2159 2160 2161 2162 2163 2164 2165 2166 2167 2168 2169 2170 2171 2172 2173 2174 2175 2176 2177 2178 2179 2180 2181 2182 2183 2184 2185 2186 2187 2188 2189 2190 2191 2192 2193 2194 2195 2196 2197 2198 2199 2200 2201 2202 2203 2204 2205 2206 2207 2208 2209 2210 2211 2212 2213 2214 2215 2216 2217 2218 2219 2220 2221 2222 2223 2224 2225 2226 2227 2228 2229 2230 2231 2232 2233 2234 2235 2236 2237 2238 2239 2240 2241 2242 2243 2244 2245 2246 2247 2248 2249 2250 2251 2252 2253 2254 2255 2256 2257 2258 2259 2260 2261 2262 2263 2264 2265 2266 2267 2268 2269 2270 2271 2272 2273 2274 2275 2276 2277 2278 2279 2280 2281 2282 2283 2284 2285 2286 2287 2288 2289 2290 2291 2292 2293 2294 2295 2296 2297 2298 2299 2300 2301 2302 2303 2304 2305 2306 2307 2308 2309 2310 2311 2312 2313 2314 2315 2316 2317 2318 2319 2320 2321 2322 2323 2324 2325 2326 2327 2328 2329 2330 2331 2332 2333 2334 2335 2336 2337 2338 2339 2340 2341 2342 2343 2344 2345 2346 2347 2348 2349 2350 2351 2352 2353 2354 2355 2356 2357 2358 2359 2360 2361 2362 2363 2364 2365 2366 2367 2368 2369 2370 2371 2372 2373 2374 2375 2376 2377 2378 2379 2380 2381 2382 2383 2384 2385 2386 2387 2388 2389 2390 2391 2392 2393 2394 2395 2396 2397 2398 2399 2400 2401 2402 2403 2404 2405 2406 2407 2408 2409 2410 2411 2412 2413 2414 2415 2416 2417 2418 2419 2420 2421 2422 2423 2424 2425 2426 2427 2428 2429 2430 2431 2432 2433 2434 2435 2436 2437 2438 2439 2440 2441 2442 2443 2444 2445 2446 2447 2448 2449 2450 2451 2452 2453 2454 2455 2456 2457 2458 2459 2460 2461 2462 2463 2464 2465 2466 2467 2468 2469 2470 2471 2472 2473 2474 2475 2476 2477 2478 2479 2480 2481 2482 2483 2484 2485 2486 2487 2488 2489 2490 2491 2492 2493 2494 2495 2496 2497 2498 2499 2500 2501 2502 2503 2504 2505 2506 2507 2508 2509 2510 2511 2512 2513 2514 2515 2516 2517 2518 2519 2520 2521 2522 2523 2524 2525 2526 2527 2528 2529 2530 2531 2532 2533 2534 2535 2536 2537 2538 2539 2540 2541 2542 2543 2544 2545 2546 2547 2548 2549 2550 2551 2552 2553 2554 2555 2556 2557 2558 2559 2560 2561 2562 2563 2564 2565 2566 2567 2568 2569 2570 2571 2572 2573 2574 2575 2576 2577 2578 2579 2580 2581 2582 2583 2584 2585 2586 2587 2588 2589 2590 2591 2592 2593 2594 2595 2596 2597 2598 2599 2600 2601 2602 2603 2604 2605 2606 2607 2608 2609 2610 2611 2612 2613 2614 2615 2616 2617 2618 2619 2620 2621 2622 2623 2624 2625 2626 2627 2628 2629 2630 2631 2632 2633 2634 2635 2636 2637 2638 2639 2640 2641 2642 2643 2644 2645 2646 2647 2648 2649 2650 2651 2652 2653 2654 2655 2656 2657 2658 2659 2660 2661 2662 2663 2664 2665 2666 2667 2668 2669 2670 2671 2672 2673 2674 2675 2676 2677 2678 2679 2680 2681 2682 2683 2684 2685 2686 2687 2688 2689 2690 2691 2692 2693 2694 2695 2696 2697 2698 2699 2700 2701 2702 2703 2704 2705 2706 2707 2708 2709 2710 2711 2712 2713 2714 2715 2716 2717 2718 2719 2720 2721 2722 2723 2724 2725 2726 2727 2728 2729 2730 2731 2732 2733 2734 2735 2736 2737 2738 2739 2740 2741 2742 2743 2744 2745 2746 2747 2748 2749 2750 2751 2752 2753 2754 2755 2756 2757 2758 2759 2760 2761 2762 2763 2764 2765 2766 2767 2768 2769 2770 2771 2772 2773 2774 2775 2776 2777 2778 2779 2780 2781 2782 2783 2784 2785 2786 2787 2788 2789 2790 2791 2792 2793 2794 2795 2796 2797 2798 2799 2800 2801 2802 2803 2804 2805 2806 2807 2808 2809 2810 2811 2812 2813 2814 2815 2816 2817 2818 2819 2820 2821 2822 2823 2824 2825 2826 2827 2828 2829 2830 2831 2832 2833 2834 2835 2836 2837 2838 2839 2840 2841 2842 2843 2844 2845 2846 2847 2848 2849 2850 2851 2852 2853 2854 2855 2856 2857 2858 2859 2860 2861 2862 2863 2864 2865 2866 2867 2868 2869 2870 2871 2872 2873 2874 2875 2876 2877 2878 2879 2880 2881 2882 2883 2884 2885 2886 2887 2888 2889 2890 2891 2892 2893 2894 2895 2896 2897 2898 2899 2900 2901 2902 2903 2904 2905 2906 2907 2908 2909 2910 2911 2912 2913 2914 2915 2916 2917 2918 2919 2920 2921 2922 2923 2924 2925 2926 2927 2928 2929 2930 2931 2932 2933 2934 2935 2936 2937 2938 2939 2940 2941 2942 2943 2944 2945 2946 2947 2948 2949 2950 2951 2952 2953 2954 2955 2956 2957 2958 2959 2960 2961 2962 2963 2964 2965 2966 2967 2968 2969 2970 2971 2972 2973 2974 2975 2976 2977 2978 2979 2980 2981 2982 2983 2984 2985 2986 2987 2988 2989 2990 2991 2992 2993 2994 2995 2996 2997 2998 2999 3000 3001 3002 3003 3004 3005 3006 3007 3008 3009 3010 3011 3012 3013 3014 3015 3016 3017 3018 3019 3020 3021 3022 3023 3024 3025 3026 3027 3028 3029 3030 3031 3032 3033 3034 3035 3036 3037 3038 3039 3040 3041 3042 3043 3044 3045 3046 3047 3048 3049 3050 3051 3052 3053 3054 3055 3056 3057 3058 3059 3060 3061 3062 3063 3064 3065 3066 3067 3068 3069 3070 3071 3072 3073 3074 3075 3076 3077 3078 3079 3080 3081 3082 3083 3084 3085 3086 3087 3088 3089 3090 3091 3092 3093 3094 3095 3096 3097 3098 3099 3100 3101 3102 3103 3104 3105 3106 3107 3108 3109 3110 3111 3112 3113 3114 3115 3116 3117 3118 3119 3120 3121 3122 3123 3124 3125 3126 3127 3128 3129 3130 3131 3132 3133 3134 3135 3136 3137 3138 3139 3140 3141 3142 3143 3144 3145 3146 3147 3148 3149 3150 3151 3152 3153 3154 3155 3156 3157 3158 3159 3160 3161 3162 3163 3164 3165 3166 3167 3168 3169 3170 3171 3172 3173 3174 3175 3176 3177 3178 3179 3180 3181 3182 3183 3184 3185 3186 3187 3188 3189 3190 3191 3192 3193 3194 3195 3196 3197 3198 3199 3200 3201 3202 3203 3204 3205 3206 3207 3208 3209 3210 3211 3212 3213 3214 3215 3216 3217 3218 3219 3220 3221 3222 3223 3224 3225 3226 3227 3228 3229 3230 3231 3232 3233 3234 3235 3236 3237 3238 3239 3240 3241 3242 3243 3244 3245 3246 3247 3248 3249 3250 3251 3252 3253 3254 3255 3256 3257 3258 3259 3260 3261 3262 3263 3264 3265 3266 3267 3268 3269 3270 3271 3272 3273 3274 3275 3276 3277 3278 3279 3280 3281 3282 3283 3284 3285 3286 3287 3288 3289 3290 3291 3292 3293 3294 3295 3296 3297 3298 3299 3300 3301 3302 3303 3304 3305 3306 3307 3308 3309 3310 3311 3312 3313 3314 3315 3316 3317 3318 3319 3320 3321 3322 3323 3324 3325 3326 3327 3328 3329 3330 3331 3332 3333 3334 3335 3336 3337 3338 3339 3340 3341 3342 3343 3344 3345 3346 3347 3348 3349 3350 3351 3352 3353 3354 3355 3356 3357 3358 3359 3360 3361 3362 3363 3364 3365 3366 3367 3368 3369 3370 3371 3372 3373 3374 3375 3376 3377 3378 3379 3380 3381 3382 3383 3384 3385 3386 3387 3388 3389 3390 3391 3392 3393 3394 3395 3396 3397 3398 3399 3400 3401 3402 3403 3404 3405 3406 3407 3408 3409 3410 3411 3412 3413 3414 3415 3416 3417 3418 3419 3420 3421 3422 3423 3424 3425 3426 3427 3428 3429 3430 3431 3432 3433 3434 3435 3436 3437 3438 3439 3440 3441 3442 3443 3444 3445 3446 3447 3448 3449 3450 3451 3452 3453 3454 3455 3456 3457 3458 3459 3460 3461 3462 3463 3464 3465 3466 3467 3468 3469 3470 3471 3472 3473 3474 3475 3476 3477 3478 3479 3480 3481 3482 3483 3484 3485 3486 3487 3488 3489 3490 3491 3492 3493 3494 3495 3496 3497 3498 3499 3500 3501 3502 3503 3504 3505 3506 3507 3508 3509 3510 3511 3512 3513 3514 3515 3516 3517 3518 3519 3520 3521 3522 3523 3524 3525 3526 3527 3528 3529 3530 3531 3532 3533 3534 3535 3536 3537 3538 3539 3540 3541 3542 3543 3544 3545 3546 3547 3548 3549 3550 3551 3552 3553 3554 3555 3556 3557 3558 3559 3560 3561 3562 3563 3564 3565 3566 3567 3568 3569 3570 3571 3572 3573 3574 3575 3576 3577 3578 3579 3580 3581 3582 3583 3584 3585 3586 3587 3588 3589 3590 3591 3592 3593 3594 3595 3596 3597 3598 3599 3600 3601 3602 3603 3604 3605 3606 3607 3608 3609 3610 3611 3612 3613 3614 3615 3616 3617 3618 3619 3620 3621 3622 3623 3624 3625 3626 3627 3628 3629 3630 3631 3632 3633 3634 3635 3636 3637 3638 3639 3640 3641 3642 3643 3644 3645 3646 3647 3648 3649 3650 3651 3652 3653 3654 3655 3656 3657 3658 3659 3660 3661 3662 3663 3664 3665 3666 3667 3668 3669 3670 3671 3672 3673 3674 3675 3676 3677 3678 3679 3680 3681 3682 3683 3684 3685 3686 3687 3688 3689 3690 3691 3692 3693 3694 3695 3696 3697 3698 3699 3700 3701 3702 3703 3704 3705 3706 3707 3708 3709 3710 3711 3712 3713 3714 3715 3716 3717 3718 3719 3720 3721 3722 3723 3724 3725 3726 3727 3728 3729 3730 3731 3732 3733 3734 3735 3736 3737 3738 3739 3740 3741 3742 3743 3744 3745 3746 3747 3748 3749 3750 3751 3752 3753 3754 3755 3756 3757 3758 3759 3760 3761 3762 3763 3764 3765 3766 3767 3768 3769 3770 3771 3772 3773 3774 3775 3776 3777 3778 3779 3780 3781 3782 3783 3784 3785 3786 3787 3788 3789 3790 3791 3792 3793 3794 3795 3796 3797 3798 3799 3800 3801 3802 3803 3804 3805 3806 3807 3808 3809 3810 3811 3812 3813 3814 3815 3816 3817 3818 3819 3820 3821 3822 3823 3824 3825 3826 3827 3828 3829 3830 3831 3832 3833 3834 3835 3836 3837 3838 3839 3840 3841 3842 3843 3844 3845 3846 3847 3848 3849 3850 3851 3852 3853 3854 3855 3856 3857 3858 3859 3860 3861 3862 3863 3864 3865 3866 3867 3868 3869 3870 3871 3872 3873 3874 3875 3876 3877 3878 3879 3880 3881 3882 3883 3884 3885 3886 3887 3888 3889 3890 3891 3892 3893 3894 3895 3896 3897 3898 3899 3900 3901 3902 3903 3904 3905 3906 3907 3908 3909 3910 3911 3912 3913 3914 3915 3916 3917 3918 3919 3920 3921 3922 3923 3924 3925 3926 3927 3928 3929 3930 3931 3932 3933 3934 3935 3936 3937 3938 3939 3940 3941 3942 3943 3944 3945 3946 3947 3948 3949 3950 3951 3952 3953 3954 3955 3956 3957 3958 3959 3960 3961 3962 3963 3964 3965 3966 3967 3968 3969 3970 3971 3972 3973 3974 3975 3976 3977 3978 3979 3980 3981 3982 3983 3984 3985 3986 3987 3988 3989 3990 3991 3992 3993 3994 3995 3996 3997 3998 3999 4000 4001 4002 4003 4004 4005 4006 4007 4008 4009 4010 4011 4012 4013 4014 4015 4016 4017 4018 4019 4020 4021 4022 4023 4024 4025 4026 4027 4028 4029 4030 4031 4032 4033 4034 4035 4036 4037 4038 4039 4040 4041 4042 4043 4044 4045 4046 4047 4048 4049 4050 4051 4052 4053 4054 4055 4056 4057 4058 4059 4060 4061 4062 4063 4064 4065 4066 4067 4068 4069 4070 4071 4072 4073 4074 4075 4076 4077 4078 4079 4080 4081 4082 4083 4084 4085 4086 4087 4088 4089 4090 4091 4092 4093 4094 4095 4096 4097 4098 4099 4100 4101 4102 4103 4104 4105 4106 4107 4108 4109 4110 4111 4112 4113 4114 4115 4116 4117 4118 4119 4120 4121 4122 4123 4124 4125 4126 4127 4128 4129 4130 4131 4132 4133 4134 4135 4136 4137 4138 4139 4140 4141 4142 4143 4144 4145 4146 4147 4148 4149 4150 4151 4152 4153 4154 4155 4156 4157 4158 4159 4160 4161
|
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width">
<meta name="nodejs.org:node-version" content="v22.14.0">
<title>Process | Node.js v22.14.0 Documentation</title>
<link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Lato:400,700,400italic&display=fallback">
<link rel="stylesheet" href="assets/style.css">
<link rel="stylesheet" href="assets/hljs.css">
<link rel="canonical" href="https://nodejs.org/api/process.html">
<script async defer src="assets/api.js" type="text/javascript"></script>
<script>
const storedTheme = localStorage.getItem('theme');
// Follow operating system theme preference
if (storedTheme === null && window.matchMedia) {
const mq = window.matchMedia('(prefers-color-scheme: dark)');
if (mq.matches) {
document.documentElement.classList.add('dark-mode');
}
} else if (storedTheme === 'dark') {
document.documentElement.classList.add('dark-mode');
}
</script>
<style>@media(max-width:542px){.with-40-chars>.js-flavor-toggle{float:none;margin:0 0 1em auto;}}@media(max-width:734px){.with-64-chars>.js-flavor-toggle{float:none;margin:0 0 1em auto;}}@media(max-width:550px){.with-41-chars>.js-flavor-toggle{float:none;margin:0 0 1em auto;}}@media(max-width:598px){.with-47-chars>.js-flavor-toggle{float:none;margin:0 0 1em auto;}}@media(max-width:582px){.with-45-chars>.js-flavor-toggle{float:none;margin:0 0 1em auto;}}@media(max-width:566px){.with-43-chars>.js-flavor-toggle{float:none;margin:0 0 1em auto;}}@media(max-width:606px){.with-48-chars>.js-flavor-toggle{float:none;margin:0 0 1em auto;}}@media(max-width:614px){.with-49-chars>.js-flavor-toggle{float:none;margin:0 0 1em auto;}}@media(max-width:694px){.with-59-chars>.js-flavor-toggle{float:none;margin:0 0 1em auto;}}@media(max-width:750px){.with-66-chars>.js-flavor-toggle{float:none;margin:0 0 1em auto;}}@media(max-width:622px){.with-50-chars>.js-flavor-toggle{float:none;margin:0 0 1em auto;}}@media(max-width:558px){.with-42-chars>.js-flavor-toggle{float:none;margin:0 0 1em auto;}}@media(max-width:574px){.with-44-chars>.js-flavor-toggle{float:none;margin:0 0 1em auto;}}</style>
</head>
<body class="alt apidoc" id="api-section-process">
<a href="#apicontent" class="skip-to-content">Skip to content</a>
<div id="content" class="clearfix">
<div role="navigation" id="column2" class="interior">
<div id="intro" class="interior">
<a href="/" title="Go back to the home page">
Node.js
</a>
</div>
<ul>
<li><a href="documentation.html" class="nav-documentation">About this documentation</a></li>
<li><a href="synopsis.html" class="nav-synopsis">Usage and example</a></li>
</ul>
<hr class="line">
<ul>
<li><a href="assert.html" class="nav-assert">Assertion testing</a></li>
<li><a href="async_context.html" class="nav-async_context">Asynchronous context tracking</a></li>
<li><a href="async_hooks.html" class="nav-async_hooks">Async hooks</a></li>
<li><a href="buffer.html" class="nav-buffer">Buffer</a></li>
<li><a href="addons.html" class="nav-addons">C++ addons</a></li>
<li><a href="n-api.html" class="nav-n-api">C/C++ addons with Node-API</a></li>
<li><a href="embedding.html" class="nav-embedding">C++ embedder API</a></li>
<li><a href="child_process.html" class="nav-child_process">Child processes</a></li>
<li><a href="cluster.html" class="nav-cluster">Cluster</a></li>
<li><a href="cli.html" class="nav-cli">Command-line options</a></li>
<li><a href="console.html" class="nav-console">Console</a></li>
<li><a href="corepack.html" class="nav-corepack">Corepack</a></li>
<li><a href="crypto.html" class="nav-crypto">Crypto</a></li>
<li><a href="debugger.html" class="nav-debugger">Debugger</a></li>
<li><a href="deprecations.html" class="nav-deprecations">Deprecated APIs</a></li>
<li><a href="diagnostics_channel.html" class="nav-diagnostics_channel">Diagnostics Channel</a></li>
<li><a href="dns.html" class="nav-dns">DNS</a></li>
<li><a href="domain.html" class="nav-domain">Domain</a></li>
<li><a href="errors.html" class="nav-errors">Errors</a></li>
<li><a href="events.html" class="nav-events">Events</a></li>
<li><a href="fs.html" class="nav-fs">File system</a></li>
<li><a href="globals.html" class="nav-globals">Globals</a></li>
<li><a href="http.html" class="nav-http">HTTP</a></li>
<li><a href="http2.html" class="nav-http2">HTTP/2</a></li>
<li><a href="https.html" class="nav-https">HTTPS</a></li>
<li><a href="inspector.html" class="nav-inspector">Inspector</a></li>
<li><a href="intl.html" class="nav-intl">Internationalization</a></li>
<li><a href="modules.html" class="nav-modules">Modules: CommonJS modules</a></li>
<li><a href="esm.html" class="nav-esm">Modules: ECMAScript modules</a></li>
<li><a href="module.html" class="nav-module">Modules: <code>node:module</code> API</a></li>
<li><a href="packages.html" class="nav-packages">Modules: Packages</a></li>
<li><a href="typescript.html" class="nav-typescript">Modules: TypeScript</a></li>
<li><a href="net.html" class="nav-net">Net</a></li>
<li><a href="os.html" class="nav-os">OS</a></li>
<li><a href="path.html" class="nav-path">Path</a></li>
<li><a href="perf_hooks.html" class="nav-perf_hooks">Performance hooks</a></li>
<li><a href="permissions.html" class="nav-permissions">Permissions</a></li>
<li><a href="process.html" class="nav-process active">Process</a></li>
<li><a href="punycode.html" class="nav-punycode">Punycode</a></li>
<li><a href="querystring.html" class="nav-querystring">Query strings</a></li>
<li><a href="readline.html" class="nav-readline">Readline</a></li>
<li><a href="repl.html" class="nav-repl">REPL</a></li>
<li><a href="report.html" class="nav-report">Report</a></li>
<li><a href="single-executable-applications.html" class="nav-single-executable-applications">Single executable applications</a></li>
<li><a href="sqlite.html" class="nav-sqlite">SQLite</a></li>
<li><a href="stream.html" class="nav-stream">Stream</a></li>
<li><a href="string_decoder.html" class="nav-string_decoder">String decoder</a></li>
<li><a href="test.html" class="nav-test">Test runner</a></li>
<li><a href="timers.html" class="nav-timers">Timers</a></li>
<li><a href="tls.html" class="nav-tls">TLS/SSL</a></li>
<li><a href="tracing.html" class="nav-tracing">Trace events</a></li>
<li><a href="tty.html" class="nav-tty">TTY</a></li>
<li><a href="dgram.html" class="nav-dgram">UDP/datagram</a></li>
<li><a href="url.html" class="nav-url">URL</a></li>
<li><a href="util.html" class="nav-util">Utilities</a></li>
<li><a href="v8.html" class="nav-v8">V8</a></li>
<li><a href="vm.html" class="nav-vm">VM</a></li>
<li><a href="wasi.html" class="nav-wasi">WASI</a></li>
<li><a href="webcrypto.html" class="nav-webcrypto">Web Crypto API</a></li>
<li><a href="webstreams.html" class="nav-webstreams">Web Streams API</a></li>
<li><a href="worker_threads.html" class="nav-worker_threads">Worker threads</a></li>
<li><a href="zlib.html" class="nav-zlib">Zlib</a></li>
</ul>
<hr class="line">
<ul>
<li><a href="https://github.com/nodejs/node" class="nav-https-github-com-nodejs-node">Code repository and issue tracker</a></li>
</ul>
</div>
<div id="column1" data-id="process" class="interior">
<header class="header">
<div class="header-container">
<h1>Node.js v22.14.0 documentation</h1>
<button class="theme-toggle-btn" id="theme-toggle-btn" title="Toggle dark mode/light mode" aria-label="Toggle dark mode/light mode" hidden>
<svg xmlns="http://www.w3.org/2000/svg" class="icon dark-icon" height="24" width="24">
<path fill="none" d="M0 0h24v24H0z" />
<path d="M11.1 12.08c-2.33-4.51-.5-8.48.53-10.07C6.27 2.2 1.98 6.59 1.98 12c0 .14.02.28.02.42.62-.27 1.29-.42 2-.42 1.66 0 3.18.83 4.1 2.15A4.01 4.01 0 0111 18c0 1.52-.87 2.83-2.12 3.51.98.32 2.03.5 3.11.5 3.5 0 6.58-1.8 8.37-4.52-2.36.23-6.98-.97-9.26-5.41z"/>
<path d="M7 16h-.18C6.4 14.84 5.3 14 4 14c-1.66 0-3 1.34-3 3s1.34 3 3 3h3c1.1 0 2-.9 2-2s-.9-2-2-2z"/>
</svg>
<svg xmlns="http://www.w3.org/2000/svg" class="icon light-icon" height="24" width="24">
<path d="M0 0h24v24H0z" fill="none" />
<path d="M6.76 4.84l-1.8-1.79-1.41 1.41 1.79 1.79 1.42-1.41zM4 10.5H1v2h3v-2zm9-9.95h-2V3.5h2V.55zm7.45 3.91l-1.41-1.41-1.79 1.79 1.41 1.41 1.79-1.79zm-3.21 13.7l1.79 1.8 1.41-1.41-1.8-1.79-1.4 1.4zM20 10.5v2h3v-2h-3zm-8-5c-3.31 0-6 2.69-6 6s2.69 6 6 6 6-2.69 6-6-2.69-6-6-6zm-1 16.95h2V19.5h-2v2.95zm-7.45-3.91l1.41 1.41 1.79-1.8-1.41-1.41-1.79 1.8z"/>
</svg>
</button>
</div>
<div id="gtoc">
<ul>
<li class="pinned-header">Node.js v22.14.0</li>
<li class="picker-header">
<a href="#toc-picker" aria-controls="toc-picker">
<span class="picker-arrow"></span>
Table of contents
</a>
<div class="picker" tabindex="-1"><div class="toc"><ul id="toc-picker">
<li><a href="#process">Process</a>
<ul>
<li><a href="#process-events">Process events</a>
<ul>
<li><a href="#event-beforeexit">Event: <code>'beforeExit'</code></a></li>
<li><a href="#event-disconnect">Event: <code>'disconnect'</code></a></li>
<li><a href="#event-exit">Event: <code>'exit'</code></a></li>
<li><a href="#event-message">Event: <code>'message'</code></a></li>
<li><span class="stability_0"><a href="#event-multipleresolves">Event: <code>'multipleResolves'</code></a></span></li>
<li><a href="#event-rejectionhandled">Event: <code>'rejectionHandled'</code></a></li>
<li><a href="#event-workermessage">Event: <code>'workerMessage'</code></a></li>
<li><a href="#event-uncaughtexception">Event: <code>'uncaughtException'</code></a>
<ul>
<li><a href="#warning-using-uncaughtexception-correctly">Warning: Using <code>'uncaughtException'</code> correctly</a></li>
</ul>
</li>
<li><a href="#event-uncaughtexceptionmonitor">Event: <code>'uncaughtExceptionMonitor'</code></a></li>
<li><a href="#event-unhandledrejection">Event: <code>'unhandledRejection'</code></a></li>
<li><a href="#event-warning">Event: <code>'warning'</code></a>
<ul>
<li><a href="#emitting-custom-warnings">Emitting custom warnings</a></li>
<li><a href="#nodejs-warning-names">Node.js warning names</a></li>
</ul>
</li>
<li><a href="#event-worker">Event: <code>'worker'</code></a></li>
<li><a href="#signal-events">Signal events</a></li>
</ul>
</li>
<li><a href="#processabort"><code>process.abort()</code></a></li>
<li><a href="#processallowednodeenvironmentflags"><code>process.allowedNodeEnvironmentFlags</code></a></li>
<li><a href="#processarch"><code>process.arch</code></a></li>
<li><a href="#processargv"><code>process.argv</code></a></li>
<li><a href="#processargv0"><code>process.argv0</code></a></li>
<li><a href="#processchannel"><code>process.channel</code></a>
<ul>
<li><a href="#processchannelref"><code>process.channel.ref()</code></a></li>
<li><a href="#processchannelunref"><code>process.channel.unref()</code></a></li>
</ul>
</li>
<li><a href="#processchdirdirectory"><code>process.chdir(directory)</code></a></li>
<li><a href="#processconfig"><code>process.config</code></a></li>
<li><a href="#processconnected"><code>process.connected</code></a></li>
<li><span class="stability_1"><a href="#processconstrainedmemory"><code>process.constrainedMemory()</code></a></span></li>
<li><span class="stability_1"><a href="#processavailablememory"><code>process.availableMemory()</code></a></span></li>
<li><a href="#processcpuusagepreviousvalue"><code>process.cpuUsage([previousValue])</code></a></li>
<li><a href="#processcwd"><code>process.cwd()</code></a></li>
<li><a href="#processdebugport"><code>process.debugPort</code></a></li>
<li><a href="#processdisconnect"><code>process.disconnect()</code></a></li>
<li><a href="#processdlopenmodule-filename-flags"><code>process.dlopen(module, filename[, flags])</code></a></li>
<li><a href="#processemitwarningwarning-options"><code>process.emitWarning(warning[, options])</code></a></li>
<li><a href="#processemitwarningwarning-type-code-ctor"><code>process.emitWarning(warning[, type[, code]][, ctor])</code></a>
<ul>
<li><a href="#avoiding-duplicate-warnings">Avoiding duplicate warnings</a></li>
</ul>
</li>
<li><a href="#processenv"><code>process.env</code></a></li>
<li><a href="#processexecargv"><code>process.execArgv</code></a></li>
<li><a href="#processexecpath"><code>process.execPath</code></a></li>
<li><a href="#processexitcode"><code>process.exit([code])</code></a></li>
<li><a href="#processexitcode_1"><code>process.exitCode</code></a></li>
<li><a href="#processfeaturescached_builtins"><code>process.features.cached_builtins</code></a></li>
<li><a href="#processfeaturesdebug"><code>process.features.debug</code></a></li>
<li><a href="#processfeaturesinspector"><code>process.features.inspector</code></a></li>
<li><span class="stability_0"><a href="#processfeaturesipv6"><code>process.features.ipv6</code></a></span></li>
<li><a href="#processfeaturesrequire_module"><code>process.features.require_module</code></a></li>
<li><a href="#processfeaturestls"><code>process.features.tls</code></a></li>
<li><span class="stability_0"><a href="#processfeaturestls_alpn"><code>process.features.tls_alpn</code></a></span></li>
<li><span class="stability_0"><a href="#processfeaturestls_ocsp"><code>process.features.tls_ocsp</code></a></span></li>
<li><span class="stability_0"><a href="#processfeaturestls_sni"><code>process.features.tls_sni</code></a></span></li>
<li><span class="stability_1"><a href="#processfeaturestypescript"><code>process.features.typescript</code></a></span></li>
<li><span class="stability_0"><a href="#processfeaturesuv"><code>process.features.uv</code></a></span></li>
<li><span class="stability_1"><a href="#processfinalizationregisterref-callback"><code>process.finalization.register(ref, callback)</code></a></span></li>
<li><span class="stability_1"><a href="#processfinalizationregisterbeforeexitref-callback"><code>process.finalization.registerBeforeExit(ref, callback)</code></a></span></li>
<li><span class="stability_1"><a href="#processfinalizationunregisterref"><code>process.finalization.unregister(ref)</code></a></span></li>
<li><span class="stability_1"><a href="#processgetactiveresourcesinfo"><code>process.getActiveResourcesInfo()</code></a></span></li>
<li><a href="#processgetbuiltinmoduleid"><code>process.getBuiltinModule(id)</code></a></li>
<li><a href="#processgetegid"><code>process.getegid()</code></a></li>
<li><a href="#processgeteuid"><code>process.geteuid()</code></a></li>
<li><a href="#processgetgid"><code>process.getgid()</code></a></li>
<li><a href="#processgetgroups"><code>process.getgroups()</code></a></li>
<li><a href="#processgetuid"><code>process.getuid()</code></a></li>
<li><a href="#processhasuncaughtexceptioncapturecallback"><code>process.hasUncaughtExceptionCaptureCallback()</code></a></li>
<li><span class="stability_3"><a href="#processhrtimetime"><code>process.hrtime([time])</code></a></span></li>
<li><a href="#processhrtimebigint"><code>process.hrtime.bigint()</code></a></li>
<li><a href="#processinitgroupsuser-extragroup"><code>process.initgroups(user, extraGroup)</code></a></li>
<li><a href="#processkillpid-signal"><code>process.kill(pid[, signal])</code></a></li>
<li><span class="stability_1"><a href="#processloadenvfilepath"><code>process.loadEnvFile(path)</code></a></span></li>
<li><span class="stability_0"><a href="#processmainmodule"><code>process.mainModule</code></a></span></li>
<li><a href="#processmemoryusage"><code>process.memoryUsage()</code></a></li>
<li><a href="#processmemoryusagerss"><code>process.memoryUsage.rss()</code></a></li>
<li><span class="stability_3"><a href="#processnexttickcallback-args"><code>process.nextTick(callback[, ...args])</code></a></span>
<ul>
<li><a href="#when-to-use-queuemicrotask-vs-processnexttick">When to use <code>queueMicrotask()</code> vs. <code>process.nextTick()</code></a></li>
</ul>
</li>
<li><a href="#processnodeprecation"><code>process.noDeprecation</code></a></li>
<li><a href="#processpermission"><code>process.permission</code></a>
<ul>
<li><a href="#processpermissionhasscope-reference"><code>process.permission.has(scope[, reference])</code></a></li>
</ul>
</li>
<li><a href="#processpid"><code>process.pid</code></a></li>
<li><a href="#processplatform"><code>process.platform</code></a></li>
<li><a href="#processppid"><code>process.ppid</code></a></li>
<li><span class="stability_1"><a href="#processrefmayberefable"><code>process.ref(maybeRefable)</code></a></span></li>
<li><a href="#processrelease"><code>process.release</code></a></li>
<li><a href="#processreport"><code>process.report</code></a>
<ul>
<li><a href="#processreportcompact"><code>process.report.compact</code></a></li>
<li><a href="#processreportdirectory"><code>process.report.directory</code></a></li>
<li><a href="#processreportfilename"><code>process.report.filename</code></a></li>
<li><a href="#processreportgetreporterr"><code>process.report.getReport([err])</code></a></li>
<li><a href="#processreportreportonfatalerror"><code>process.report.reportOnFatalError</code></a></li>
<li><a href="#processreportreportonsignal"><code>process.report.reportOnSignal</code></a></li>
<li><a href="#processreportreportonuncaughtexception"><code>process.report.reportOnUncaughtException</code></a></li>
<li><a href="#processreportexcludeenv"><code>process.report.excludeEnv</code></a></li>
<li><a href="#processreportsignal"><code>process.report.signal</code></a></li>
<li><a href="#processreportwritereportfilename-err"><code>process.report.writeReport([filename][, err])</code></a></li>
</ul>
</li>
<li><a href="#processresourceusage"><code>process.resourceUsage()</code></a></li>
<li><a href="#processsendmessage-sendhandle-options-callback"><code>process.send(message[, sendHandle[, options]][, callback])</code></a></li>
<li><a href="#processsetegidid"><code>process.setegid(id)</code></a></li>
<li><a href="#processseteuidid"><code>process.seteuid(id)</code></a></li>
<li><a href="#processsetgidid"><code>process.setgid(id)</code></a></li>
<li><a href="#processsetgroupsgroups"><code>process.setgroups(groups)</code></a></li>
<li><a href="#processsetuidid"><code>process.setuid(id)</code></a></li>
<li><span class="stability_1"><a href="#processsetsourcemapsenabledval"><code>process.setSourceMapsEnabled(val)</code></a></span></li>
<li><a href="#processsetuncaughtexceptioncapturecallbackfn"><code>process.setUncaughtExceptionCaptureCallback(fn)</code></a></li>
<li><span class="stability_1"><a href="#processsourcemapsenabled"><code>process.sourceMapsEnabled</code></a></span></li>
<li><a href="#processstderr"><code>process.stderr</code></a>
<ul>
<li><a href="#processstderrfd"><code>process.stderr.fd</code></a></li>
</ul>
</li>
<li><a href="#processstdin"><code>process.stdin</code></a>
<ul>
<li><a href="#processstdinfd"><code>process.stdin.fd</code></a></li>
</ul>
</li>
<li><a href="#processstdout"><code>process.stdout</code></a>
<ul>
<li><a href="#processstdoutfd"><code>process.stdout.fd</code></a></li>
<li><a href="#a-note-on-process-io">A note on process I/O</a></li>
</ul>
</li>
<li><a href="#processthrowdeprecation"><code>process.throwDeprecation</code></a></li>
<li><a href="#processtitle"><code>process.title</code></a></li>
<li><a href="#processtracedeprecation"><code>process.traceDeprecation</code></a></li>
<li><span class="stability_0"><a href="#processumask"><code>process.umask()</code></a></span></li>
<li><a href="#processumaskmask"><code>process.umask(mask)</code></a></li>
<li><span class="stability_1"><a href="#processunrefmayberefable"><code>process.unref(maybeRefable)</code></a></span></li>
<li><a href="#processuptime"><code>process.uptime()</code></a></li>
<li><a href="#processversion"><code>process.version</code></a></li>
<li><a href="#processversions"><code>process.versions</code></a></li>
<li><a href="#exit-codes">Exit codes</a></li>
</ul>
</li>
</ul></div></div>
</li>
<li class="picker-header">
<a href="#gtoc-picker" aria-controls="gtoc-picker">
<span class="picker-arrow"></span>
Index
</a>
<div class="picker" tabindex="-1" id="gtoc-picker"><ul>
<li><a href="documentation.html" class="nav-documentation">About this documentation</a></li>
<li><a href="synopsis.html" class="nav-synopsis">Usage and example</a></li>
<li>
<a href="index.html">Index</a>
</li>
</ul>
<hr class="line">
<ul>
<li><a href="assert.html" class="nav-assert">Assertion testing</a></li>
<li><a href="async_context.html" class="nav-async_context">Asynchronous context tracking</a></li>
<li><a href="async_hooks.html" class="nav-async_hooks">Async hooks</a></li>
<li><a href="buffer.html" class="nav-buffer">Buffer</a></li>
<li><a href="addons.html" class="nav-addons">C++ addons</a></li>
<li><a href="n-api.html" class="nav-n-api">C/C++ addons with Node-API</a></li>
<li><a href="embedding.html" class="nav-embedding">C++ embedder API</a></li>
<li><a href="child_process.html" class="nav-child_process">Child processes</a></li>
<li><a href="cluster.html" class="nav-cluster">Cluster</a></li>
<li><a href="cli.html" class="nav-cli">Command-line options</a></li>
<li><a href="console.html" class="nav-console">Console</a></li>
<li><a href="corepack.html" class="nav-corepack">Corepack</a></li>
<li><a href="crypto.html" class="nav-crypto">Crypto</a></li>
<li><a href="debugger.html" class="nav-debugger">Debugger</a></li>
<li><a href="deprecations.html" class="nav-deprecations">Deprecated APIs</a></li>
<li><a href="diagnostics_channel.html" class="nav-diagnostics_channel">Diagnostics Channel</a></li>
<li><a href="dns.html" class="nav-dns">DNS</a></li>
<li><a href="domain.html" class="nav-domain">Domain</a></li>
<li><a href="errors.html" class="nav-errors">Errors</a></li>
<li><a href="events.html" class="nav-events">Events</a></li>
<li><a href="fs.html" class="nav-fs">File system</a></li>
<li><a href="globals.html" class="nav-globals">Globals</a></li>
<li><a href="http.html" class="nav-http">HTTP</a></li>
<li><a href="http2.html" class="nav-http2">HTTP/2</a></li>
<li><a href="https.html" class="nav-https">HTTPS</a></li>
<li><a href="inspector.html" class="nav-inspector">Inspector</a></li>
<li><a href="intl.html" class="nav-intl">Internationalization</a></li>
<li><a href="modules.html" class="nav-modules">Modules: CommonJS modules</a></li>
<li><a href="esm.html" class="nav-esm">Modules: ECMAScript modules</a></li>
<li><a href="module.html" class="nav-module">Modules: <code>node:module</code> API</a></li>
<li><a href="packages.html" class="nav-packages">Modules: Packages</a></li>
<li><a href="typescript.html" class="nav-typescript">Modules: TypeScript</a></li>
<li><a href="net.html" class="nav-net">Net</a></li>
<li><a href="os.html" class="nav-os">OS</a></li>
<li><a href="path.html" class="nav-path">Path</a></li>
<li><a href="perf_hooks.html" class="nav-perf_hooks">Performance hooks</a></li>
<li><a href="permissions.html" class="nav-permissions">Permissions</a></li>
<li><a href="process.html" class="nav-process active">Process</a></li>
<li><a href="punycode.html" class="nav-punycode">Punycode</a></li>
<li><a href="querystring.html" class="nav-querystring">Query strings</a></li>
<li><a href="readline.html" class="nav-readline">Readline</a></li>
<li><a href="repl.html" class="nav-repl">REPL</a></li>
<li><a href="report.html" class="nav-report">Report</a></li>
<li><a href="single-executable-applications.html" class="nav-single-executable-applications">Single executable applications</a></li>
<li><a href="sqlite.html" class="nav-sqlite">SQLite</a></li>
<li><a href="stream.html" class="nav-stream">Stream</a></li>
<li><a href="string_decoder.html" class="nav-string_decoder">String decoder</a></li>
<li><a href="test.html" class="nav-test">Test runner</a></li>
<li><a href="timers.html" class="nav-timers">Timers</a></li>
<li><a href="tls.html" class="nav-tls">TLS/SSL</a></li>
<li><a href="tracing.html" class="nav-tracing">Trace events</a></li>
<li><a href="tty.html" class="nav-tty">TTY</a></li>
<li><a href="dgram.html" class="nav-dgram">UDP/datagram</a></li>
<li><a href="url.html" class="nav-url">URL</a></li>
<li><a href="util.html" class="nav-util">Utilities</a></li>
<li><a href="v8.html" class="nav-v8">V8</a></li>
<li><a href="vm.html" class="nav-vm">VM</a></li>
<li><a href="wasi.html" class="nav-wasi">WASI</a></li>
<li><a href="webcrypto.html" class="nav-webcrypto">Web Crypto API</a></li>
<li><a href="webstreams.html" class="nav-webstreams">Web Streams API</a></li>
<li><a href="worker_threads.html" class="nav-worker_threads">Worker threads</a></li>
<li><a href="zlib.html" class="nav-zlib">Zlib</a></li>
</ul>
<hr class="line">
<ul>
<li><a href="https://github.com/nodejs/node" class="nav-https-github-com-nodejs-node">Code repository and issue tracker</a></li>
</ul></div>
</li>
<li class="picker-header">
<a href="#alt-docs" aria-controls="alt-docs">
<span class="picker-arrow"></span>
Other versions
</a>
<div class="picker" tabindex="-1"><ol id="alt-docs"><li><a href="https://nodejs.org/docs/latest-v23.x/api/process.html">23.x</a></li>
<li><a href="https://nodejs.org/docs/latest-v22.x/api/process.html">22.x <b>LTS</b></a></li>
<li><a href="https://nodejs.org/docs/latest-v21.x/api/process.html">21.x</a></li>
<li><a href="https://nodejs.org/docs/latest-v20.x/api/process.html">20.x <b>LTS</b></a></li>
<li><a href="https://nodejs.org/docs/latest-v19.x/api/process.html">19.x</a></li>
<li><a href="https://nodejs.org/docs/latest-v18.x/api/process.html">18.x <b>LTS</b></a></li>
<li><a href="https://nodejs.org/docs/latest-v17.x/api/process.html">17.x</a></li>
<li><a href="https://nodejs.org/docs/latest-v16.x/api/process.html">16.x</a></li>
<li><a href="https://nodejs.org/docs/latest-v15.x/api/process.html">15.x</a></li>
<li><a href="https://nodejs.org/docs/latest-v14.x/api/process.html">14.x</a></li>
<li><a href="https://nodejs.org/docs/latest-v13.x/api/process.html">13.x</a></li>
<li><a href="https://nodejs.org/docs/latest-v12.x/api/process.html">12.x</a></li>
<li><a href="https://nodejs.org/docs/latest-v11.x/api/process.html">11.x</a></li>
<li><a href="https://nodejs.org/docs/latest-v10.x/api/process.html">10.x</a></li>
<li><a href="https://nodejs.org/docs/latest-v9.x/api/process.html">9.x</a></li>
<li><a href="https://nodejs.org/docs/latest-v8.x/api/process.html">8.x</a></li>
<li><a href="https://nodejs.org/docs/latest-v7.x/api/process.html">7.x</a></li>
<li><a href="https://nodejs.org/docs/latest-v6.x/api/process.html">6.x</a></li>
<li><a href="https://nodejs.org/docs/latest-v5.x/api/process.html">5.x</a></li>
<li><a href="https://nodejs.org/docs/latest-v4.x/api/process.html">4.x</a></li>
<li><a href="https://nodejs.org/docs/latest-v0.12.x/api/process.html">0.12.x</a></li>
<li><a href="https://nodejs.org/docs/latest-v0.10.x/api/process.html">0.10.x</a></li></ol></div>
</li>
<li class="picker-header">
<a href="#options-picker" aria-controls="options-picker">
<span class="picker-arrow"></span>
Options
</a>
<div class="picker" tabindex="-1">
<ul id="options-picker">
<li>
<a href="all.html">View on single page</a>
</li>
<li>
<a href="process.json">View as JSON</a>
</li>
<li class="edit_on_github"><a href="https://github.com/nodejs/node/edit/main/doc/api/process.md">Edit on GitHub</a></li>
</ul>
</div>
</li>
</ul>
</div>
<hr>
</header>
<details role="navigation" id="toc" open><summary>Table of contents</summary><ul>
<li><a href="#process">Process</a>
<ul>
<li><a href="#process-events">Process events</a>
<ul>
<li><a href="#event-beforeexit">Event: <code>'beforeExit'</code></a></li>
<li><a href="#event-disconnect">Event: <code>'disconnect'</code></a></li>
<li><a href="#event-exit">Event: <code>'exit'</code></a></li>
<li><a href="#event-message">Event: <code>'message'</code></a></li>
<li><span class="stability_0"><a href="#event-multipleresolves">Event: <code>'multipleResolves'</code></a></span></li>
<li><a href="#event-rejectionhandled">Event: <code>'rejectionHandled'</code></a></li>
<li><a href="#event-workermessage">Event: <code>'workerMessage'</code></a></li>
<li><a href="#event-uncaughtexception">Event: <code>'uncaughtException'</code></a>
<ul>
<li><a href="#warning-using-uncaughtexception-correctly">Warning: Using <code>'uncaughtException'</code> correctly</a></li>
</ul>
</li>
<li><a href="#event-uncaughtexceptionmonitor">Event: <code>'uncaughtExceptionMonitor'</code></a></li>
<li><a href="#event-unhandledrejection">Event: <code>'unhandledRejection'</code></a></li>
<li><a href="#event-warning">Event: <code>'warning'</code></a>
<ul>
<li><a href="#emitting-custom-warnings">Emitting custom warnings</a></li>
<li><a href="#nodejs-warning-names">Node.js warning names</a></li>
</ul>
</li>
<li><a href="#event-worker">Event: <code>'worker'</code></a></li>
<li><a href="#signal-events">Signal events</a></li>
</ul>
</li>
<li><a href="#processabort"><code>process.abort()</code></a></li>
<li><a href="#processallowednodeenvironmentflags"><code>process.allowedNodeEnvironmentFlags</code></a></li>
<li><a href="#processarch"><code>process.arch</code></a></li>
<li><a href="#processargv"><code>process.argv</code></a></li>
<li><a href="#processargv0"><code>process.argv0</code></a></li>
<li><a href="#processchannel"><code>process.channel</code></a>
<ul>
<li><a href="#processchannelref"><code>process.channel.ref()</code></a></li>
<li><a href="#processchannelunref"><code>process.channel.unref()</code></a></li>
</ul>
</li>
<li><a href="#processchdirdirectory"><code>process.chdir(directory)</code></a></li>
<li><a href="#processconfig"><code>process.config</code></a></li>
<li><a href="#processconnected"><code>process.connected</code></a></li>
<li><span class="stability_1"><a href="#processconstrainedmemory"><code>process.constrainedMemory()</code></a></span></li>
<li><span class="stability_1"><a href="#processavailablememory"><code>process.availableMemory()</code></a></span></li>
<li><a href="#processcpuusagepreviousvalue"><code>process.cpuUsage([previousValue])</code></a></li>
<li><a href="#processcwd"><code>process.cwd()</code></a></li>
<li><a href="#processdebugport"><code>process.debugPort</code></a></li>
<li><a href="#processdisconnect"><code>process.disconnect()</code></a></li>
<li><a href="#processdlopenmodule-filename-flags"><code>process.dlopen(module, filename[, flags])</code></a></li>
<li><a href="#processemitwarningwarning-options"><code>process.emitWarning(warning[, options])</code></a></li>
<li><a href="#processemitwarningwarning-type-code-ctor"><code>process.emitWarning(warning[, type[, code]][, ctor])</code></a>
<ul>
<li><a href="#avoiding-duplicate-warnings">Avoiding duplicate warnings</a></li>
</ul>
</li>
<li><a href="#processenv"><code>process.env</code></a></li>
<li><a href="#processexecargv"><code>process.execArgv</code></a></li>
<li><a href="#processexecpath"><code>process.execPath</code></a></li>
<li><a href="#processexitcode"><code>process.exit([code])</code></a></li>
<li><a href="#processexitcode_1"><code>process.exitCode</code></a></li>
<li><a href="#processfeaturescached_builtins"><code>process.features.cached_builtins</code></a></li>
<li><a href="#processfeaturesdebug"><code>process.features.debug</code></a></li>
<li><a href="#processfeaturesinspector"><code>process.features.inspector</code></a></li>
<li><span class="stability_0"><a href="#processfeaturesipv6"><code>process.features.ipv6</code></a></span></li>
<li><a href="#processfeaturesrequire_module"><code>process.features.require_module</code></a></li>
<li><a href="#processfeaturestls"><code>process.features.tls</code></a></li>
<li><span class="stability_0"><a href="#processfeaturestls_alpn"><code>process.features.tls_alpn</code></a></span></li>
<li><span class="stability_0"><a href="#processfeaturestls_ocsp"><code>process.features.tls_ocsp</code></a></span></li>
<li><span class="stability_0"><a href="#processfeaturestls_sni"><code>process.features.tls_sni</code></a></span></li>
<li><span class="stability_1"><a href="#processfeaturestypescript"><code>process.features.typescript</code></a></span></li>
<li><span class="stability_0"><a href="#processfeaturesuv"><code>process.features.uv</code></a></span></li>
<li><span class="stability_1"><a href="#processfinalizationregisterref-callback"><code>process.finalization.register(ref, callback)</code></a></span></li>
<li><span class="stability_1"><a href="#processfinalizationregisterbeforeexitref-callback"><code>process.finalization.registerBeforeExit(ref, callback)</code></a></span></li>
<li><span class="stability_1"><a href="#processfinalizationunregisterref"><code>process.finalization.unregister(ref)</code></a></span></li>
<li><span class="stability_1"><a href="#processgetactiveresourcesinfo"><code>process.getActiveResourcesInfo()</code></a></span></li>
<li><a href="#processgetbuiltinmoduleid"><code>process.getBuiltinModule(id)</code></a></li>
<li><a href="#processgetegid"><code>process.getegid()</code></a></li>
<li><a href="#processgeteuid"><code>process.geteuid()</code></a></li>
<li><a href="#processgetgid"><code>process.getgid()</code></a></li>
<li><a href="#processgetgroups"><code>process.getgroups()</code></a></li>
<li><a href="#processgetuid"><code>process.getuid()</code></a></li>
<li><a href="#processhasuncaughtexceptioncapturecallback"><code>process.hasUncaughtExceptionCaptureCallback()</code></a></li>
<li><span class="stability_3"><a href="#processhrtimetime"><code>process.hrtime([time])</code></a></span></li>
<li><a href="#processhrtimebigint"><code>process.hrtime.bigint()</code></a></li>
<li><a href="#processinitgroupsuser-extragroup"><code>process.initgroups(user, extraGroup)</code></a></li>
<li><a href="#processkillpid-signal"><code>process.kill(pid[, signal])</code></a></li>
<li><span class="stability_1"><a href="#processloadenvfilepath"><code>process.loadEnvFile(path)</code></a></span></li>
<li><span class="stability_0"><a href="#processmainmodule"><code>process.mainModule</code></a></span></li>
<li><a href="#processmemoryusage"><code>process.memoryUsage()</code></a></li>
<li><a href="#processmemoryusagerss"><code>process.memoryUsage.rss()</code></a></li>
<li><span class="stability_3"><a href="#processnexttickcallback-args"><code>process.nextTick(callback[, ...args])</code></a></span>
<ul>
<li><a href="#when-to-use-queuemicrotask-vs-processnexttick">When to use <code>queueMicrotask()</code> vs. <code>process.nextTick()</code></a></li>
</ul>
</li>
<li><a href="#processnodeprecation"><code>process.noDeprecation</code></a></li>
<li><a href="#processpermission"><code>process.permission</code></a>
<ul>
<li><a href="#processpermissionhasscope-reference"><code>process.permission.has(scope[, reference])</code></a></li>
</ul>
</li>
<li><a href="#processpid"><code>process.pid</code></a></li>
<li><a href="#processplatform"><code>process.platform</code></a></li>
<li><a href="#processppid"><code>process.ppid</code></a></li>
<li><span class="stability_1"><a href="#processrefmayberefable"><code>process.ref(maybeRefable)</code></a></span></li>
<li><a href="#processrelease"><code>process.release</code></a></li>
<li><a href="#processreport"><code>process.report</code></a>
<ul>
<li><a href="#processreportcompact"><code>process.report.compact</code></a></li>
<li><a href="#processreportdirectory"><code>process.report.directory</code></a></li>
<li><a href="#processreportfilename"><code>process.report.filename</code></a></li>
<li><a href="#processreportgetreporterr"><code>process.report.getReport([err])</code></a></li>
<li><a href="#processreportreportonfatalerror"><code>process.report.reportOnFatalError</code></a></li>
<li><a href="#processreportreportonsignal"><code>process.report.reportOnSignal</code></a></li>
<li><a href="#processreportreportonuncaughtexception"><code>process.report.reportOnUncaughtException</code></a></li>
<li><a href="#processreportexcludeenv"><code>process.report.excludeEnv</code></a></li>
<li><a href="#processreportsignal"><code>process.report.signal</code></a></li>
<li><a href="#processreportwritereportfilename-err"><code>process.report.writeReport([filename][, err])</code></a></li>
</ul>
</li>
<li><a href="#processresourceusage"><code>process.resourceUsage()</code></a></li>
<li><a href="#processsendmessage-sendhandle-options-callback"><code>process.send(message[, sendHandle[, options]][, callback])</code></a></li>
<li><a href="#processsetegidid"><code>process.setegid(id)</code></a></li>
<li><a href="#processseteuidid"><code>process.seteuid(id)</code></a></li>
<li><a href="#processsetgidid"><code>process.setgid(id)</code></a></li>
<li><a href="#processsetgroupsgroups"><code>process.setgroups(groups)</code></a></li>
<li><a href="#processsetuidid"><code>process.setuid(id)</code></a></li>
<li><span class="stability_1"><a href="#processsetsourcemapsenabledval"><code>process.setSourceMapsEnabled(val)</code></a></span></li>
<li><a href="#processsetuncaughtexceptioncapturecallbackfn"><code>process.setUncaughtExceptionCaptureCallback(fn)</code></a></li>
<li><span class="stability_1"><a href="#processsourcemapsenabled"><code>process.sourceMapsEnabled</code></a></span></li>
<li><a href="#processstderr"><code>process.stderr</code></a>
<ul>
<li><a href="#processstderrfd"><code>process.stderr.fd</code></a></li>
</ul>
</li>
<li><a href="#processstdin"><code>process.stdin</code></a>
<ul>
<li><a href="#processstdinfd"><code>process.stdin.fd</code></a></li>
</ul>
</li>
<li><a href="#processstdout"><code>process.stdout</code></a>
<ul>
<li><a href="#processstdoutfd"><code>process.stdout.fd</code></a></li>
<li><a href="#a-note-on-process-io">A note on process I/O</a></li>
</ul>
</li>
<li><a href="#processthrowdeprecation"><code>process.throwDeprecation</code></a></li>
<li><a href="#processtitle"><code>process.title</code></a></li>
<li><a href="#processtracedeprecation"><code>process.traceDeprecation</code></a></li>
<li><span class="stability_0"><a href="#processumask"><code>process.umask()</code></a></span></li>
<li><a href="#processumaskmask"><code>process.umask(mask)</code></a></li>
<li><span class="stability_1"><a href="#processunrefmayberefable"><code>process.unref(maybeRefable)</code></a></span></li>
<li><a href="#processuptime"><code>process.uptime()</code></a></li>
<li><a href="#processversion"><code>process.version</code></a></li>
<li><a href="#processversions"><code>process.versions</code></a></li>
<li><a href="#exit-codes">Exit codes</a></li>
</ul>
</li>
</ul></details>
<div role="main" id="apicontent">
<h2>Process<span><a class="mark" href="#process" id="process">#</a></span><a aria-hidden="true" class="legacy" id="process_process"></a></h2>
<p><strong>Source Code:</strong> <a href="https://github.com/nodejs/node/blob/v22.14.0/lib/process.js">lib/process.js</a></p>
<p>The <code>process</code> object provides information about, and control over, the current
Node.js process.</p>
<pre class="with-40-chars"><input class="js-flavor-toggle" type="checkbox" checked aria-label="Show modern ES modules syntax"><code class="language-js mjs"><span class="hljs-keyword">import</span> process <span class="hljs-keyword">from</span> <span class="hljs-string">'node:process'</span>;</code><code class="language-js cjs"><span class="hljs-keyword">const</span> process = <span class="hljs-built_in">require</span>(<span class="hljs-string">'node:process'</span>);</code><button class="copy-button">copy</button></pre>
<section><h3>Process events<span><a class="mark" href="#process-events" id="process-events">#</a></span><a aria-hidden="true" class="legacy" id="process_process_events"></a></h3>
<p>The <code>process</code> object is an instance of <a href="events.html#class-eventemitter"><code>EventEmitter</code></a>.</p>
<h4>Event: <code>'beforeExit'</code><span><a class="mark" href="#event-beforeexit" id="event-beforeexit">#</a></span><a aria-hidden="true" class="legacy" id="process_event_beforeexit"></a></h4>
<div class="api_metadata">
<span>Added in: v0.11.12</span>
</div>
<p>The <code>'beforeExit'</code> event is emitted when Node.js empties its event loop and has
no additional work to schedule. Normally, the Node.js process will exit when
there is no work scheduled, but a listener registered on the <code>'beforeExit'</code>
event can make asynchronous calls, and thereby cause the Node.js process to
continue.</p>
<p>The listener callback function is invoked with the value of
<a href="#processexitcode_1"><code>process.exitCode</code></a> passed as the only argument.</p>
<p>The <code>'beforeExit'</code> event is <em>not</em> emitted for conditions causing explicit
termination, such as calling <a href="#processexitcode"><code>process.exit()</code></a> or uncaught exceptions.</p>
<p>The <code>'beforeExit'</code> should <em>not</em> be used as an alternative to the <code>'exit'</code> event
unless the intention is to schedule additional work.</p>
<pre class="with-40-chars"><input class="js-flavor-toggle" type="checkbox" checked aria-label="Show modern ES modules syntax"><code class="language-js mjs"><span class="hljs-keyword">import</span> process <span class="hljs-keyword">from</span> <span class="hljs-string">'node:process'</span>;
process.<span class="hljs-title function_">on</span>(<span class="hljs-string">'beforeExit'</span>, <span class="hljs-function">(<span class="hljs-params">code</span>) =></span> {
<span class="hljs-variable language_">console</span>.<span class="hljs-title function_">log</span>(<span class="hljs-string">'Process beforeExit event with code: '</span>, code);
});
process.<span class="hljs-title function_">on</span>(<span class="hljs-string">'exit'</span>, <span class="hljs-function">(<span class="hljs-params">code</span>) =></span> {
<span class="hljs-variable language_">console</span>.<span class="hljs-title function_">log</span>(<span class="hljs-string">'Process exit event with code: '</span>, code);
});
<span class="hljs-variable language_">console</span>.<span class="hljs-title function_">log</span>(<span class="hljs-string">'This message is displayed first.'</span>);
<span class="hljs-comment">// Prints:</span>
<span class="hljs-comment">// This message is displayed first.</span>
<span class="hljs-comment">// Process beforeExit event with code: 0</span>
<span class="hljs-comment">// Process exit event with code: 0</span></code><code class="language-js cjs"><span class="hljs-keyword">const</span> process = <span class="hljs-built_in">require</span>(<span class="hljs-string">'node:process'</span>);
process.<span class="hljs-title function_">on</span>(<span class="hljs-string">'beforeExit'</span>, <span class="hljs-function">(<span class="hljs-params">code</span>) =></span> {
<span class="hljs-variable language_">console</span>.<span class="hljs-title function_">log</span>(<span class="hljs-string">'Process beforeExit event with code: '</span>, code);
});
process.<span class="hljs-title function_">on</span>(<span class="hljs-string">'exit'</span>, <span class="hljs-function">(<span class="hljs-params">code</span>) =></span> {
<span class="hljs-variable language_">console</span>.<span class="hljs-title function_">log</span>(<span class="hljs-string">'Process exit event with code: '</span>, code);
});
<span class="hljs-variable language_">console</span>.<span class="hljs-title function_">log</span>(<span class="hljs-string">'This message is displayed first.'</span>);
<span class="hljs-comment">// Prints:</span>
<span class="hljs-comment">// This message is displayed first.</span>
<span class="hljs-comment">// Process beforeExit event with code: 0</span>
<span class="hljs-comment">// Process exit event with code: 0</span></code><button class="copy-button">copy</button></pre>
<h4>Event: <code>'disconnect'</code><span><a class="mark" href="#event-disconnect" id="event-disconnect">#</a></span><a aria-hidden="true" class="legacy" id="process_event_disconnect"></a></h4>
<div class="api_metadata">
<span>Added in: v0.7.7</span>
</div>
<p>If the Node.js process is spawned with an IPC channel (see the <a href="child_process.html">Child Process</a>
and <a href="cluster.html">Cluster</a> documentation), the <code>'disconnect'</code> event will be emitted when
the IPC channel is closed.</p>
<h4>Event: <code>'exit'</code><span><a class="mark" href="#event-exit" id="event-exit">#</a></span><a aria-hidden="true" class="legacy" id="process_event_exit"></a></h4>
<div class="api_metadata">
<span>Added in: v0.1.7</span>
</div>
<ul>
<li><code>code</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type" class="type"><integer></a></li>
</ul>
<p>The <code>'exit'</code> event is emitted when the Node.js process is about to exit as a
result of either:</p>
<ul>
<li>The <code>process.exit()</code> method being called explicitly;</li>
<li>The Node.js event loop no longer having any additional work to perform.</li>
</ul>
<p>There is no way to prevent the exiting of the event loop at this point, and once
all <code>'exit'</code> listeners have finished running the Node.js process will terminate.</p>
<p>The listener callback function is invoked with the exit code specified either
by the <a href="#processexitcode_1"><code>process.exitCode</code></a> property, or the <code>exitCode</code> argument passed to the
<a href="#processexitcode"><code>process.exit()</code></a> method.</p>
<pre class="with-40-chars"><input class="js-flavor-toggle" type="checkbox" checked aria-label="Show modern ES modules syntax"><code class="language-js mjs"><span class="hljs-keyword">import</span> process <span class="hljs-keyword">from</span> <span class="hljs-string">'node:process'</span>;
process.<span class="hljs-title function_">on</span>(<span class="hljs-string">'exit'</span>, <span class="hljs-function">(<span class="hljs-params">code</span>) =></span> {
<span class="hljs-variable language_">console</span>.<span class="hljs-title function_">log</span>(<span class="hljs-string">`About to exit with code: <span class="hljs-subst">${code}</span>`</span>);
});</code><code class="language-js cjs"><span class="hljs-keyword">const</span> process = <span class="hljs-built_in">require</span>(<span class="hljs-string">'node:process'</span>);
process.<span class="hljs-title function_">on</span>(<span class="hljs-string">'exit'</span>, <span class="hljs-function">(<span class="hljs-params">code</span>) =></span> {
<span class="hljs-variable language_">console</span>.<span class="hljs-title function_">log</span>(<span class="hljs-string">`About to exit with code: <span class="hljs-subst">${code}</span>`</span>);
});</code><button class="copy-button">copy</button></pre>
<p>Listener functions <strong>must</strong> only perform <strong>synchronous</strong> operations. The Node.js
process will exit immediately after calling the <code>'exit'</code> event listeners
causing any additional work still queued in the event loop to be abandoned.
In the following example, for instance, the timeout will never occur:</p>
<pre class="with-40-chars"><input class="js-flavor-toggle" type="checkbox" checked aria-label="Show modern ES modules syntax"><code class="language-js mjs"><span class="hljs-keyword">import</span> process <span class="hljs-keyword">from</span> <span class="hljs-string">'node:process'</span>;
process.<span class="hljs-title function_">on</span>(<span class="hljs-string">'exit'</span>, <span class="hljs-function">(<span class="hljs-params">code</span>) =></span> {
<span class="hljs-built_in">setTimeout</span>(<span class="hljs-function">() =></span> {
<span class="hljs-variable language_">console</span>.<span class="hljs-title function_">log</span>(<span class="hljs-string">'This will not run'</span>);
}, <span class="hljs-number">0</span>);
});</code><code class="language-js cjs"><span class="hljs-keyword">const</span> process = <span class="hljs-built_in">require</span>(<span class="hljs-string">'node:process'</span>);
process.<span class="hljs-title function_">on</span>(<span class="hljs-string">'exit'</span>, <span class="hljs-function">(<span class="hljs-params">code</span>) =></span> {
<span class="hljs-built_in">setTimeout</span>(<span class="hljs-function">() =></span> {
<span class="hljs-variable language_">console</span>.<span class="hljs-title function_">log</span>(<span class="hljs-string">'This will not run'</span>);
}, <span class="hljs-number">0</span>);
});</code><button class="copy-button">copy</button></pre>
<h4>Event: <code>'message'</code><span><a class="mark" href="#event-message" id="event-message">#</a></span><a aria-hidden="true" class="legacy" id="process_event_message"></a></h4>
<div class="api_metadata">
<span>Added in: v0.5.10</span>
</div>
<ul>
<li><code>message</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object" class="type"><Object></a> | <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Boolean_type" class="type"><boolean></a> | <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type" class="type"><number></a> | <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type"><string></a> | <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Null_type" class="type"><null></a> a parsed JSON object
or a serializable primitive value.</li>
<li><code>sendHandle</code> <a href="net.html#class-netserver" class="type"><net.Server></a> | <a href="net.html#class-netsocket" class="type"><net.Socket></a> a <a href="net.html#class-netserver"><code>net.Server</code></a> or <a href="net.html#class-netsocket"><code>net.Socket</code></a>
object, or undefined.</li>
</ul>
<p>If the Node.js process is spawned with an IPC channel (see the <a href="child_process.html">Child Process</a>
and <a href="cluster.html">Cluster</a> documentation), the <code>'message'</code> event is emitted whenever a
message sent by a parent process using <a href="child_process.html#subprocesssendmessage-sendhandle-options-callback"><code>childprocess.send()</code></a> is received by
the child process.</p>
<p>The message goes through serialization and parsing. The resulting message might
not be the same as what is originally sent.</p>
<p>If the <code>serialization</code> option was set to <code>advanced</code> used when spawning the
process, the <code>message</code> argument can contain data that JSON is not able
to represent.
See <a href="child_process.html#advanced-serialization">Advanced serialization for <code>child_process</code></a> for more details.</p>
<h4>Event: <code>'multipleResolves'</code><span><a class="mark" href="#event-multipleresolves" id="event-multipleresolves">#</a></span><a aria-hidden="true" class="legacy" id="process_event_multipleresolves"></a></h4>
<div class="api_metadata">
<span>Added in: v10.12.0</span><span>Deprecated since: v17.6.0, v16.15.0</span>
</div>
<p></p><div class="api_stability api_stability_0"><a href="documentation.html#stability-index">Stability: 0</a> - Deprecated</div><p></p>
<ul>
<li><code>type</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type"><string></a> The resolution type. One of <code>'resolve'</code> or <code>'reject'</code>.</li>
<li><code>promise</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise" class="type"><Promise></a> The promise that resolved or rejected more than once.</li>
<li><code>value</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Data_types" class="type"><any></a> The value with which the promise was either resolved or
rejected after the original resolve.</li>
</ul>
<p>The <code>'multipleResolves'</code> event is emitted whenever a <code>Promise</code> has been either:</p>
<ul>
<li>Resolved more than once.</li>
<li>Rejected more than once.</li>
<li>Rejected after resolve.</li>
<li>Resolved after reject.</li>
</ul>
<p>This is useful for tracking potential errors in an application while using the
<code>Promise</code> constructor, as multiple resolutions are silently swallowed. However,
the occurrence of this event does not necessarily indicate an error. For
example, <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise/race"><code>Promise.race()</code></a> can trigger a <code>'multipleResolves'</code> event.</p>
<p>Because of the unreliability of the event in cases like the
<a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise/race"><code>Promise.race()</code></a> example above it has been deprecated.</p>
<pre class="with-40-chars"><input class="js-flavor-toggle" type="checkbox" checked aria-label="Show modern ES modules syntax"><code class="language-js mjs"><span class="hljs-keyword">import</span> process <span class="hljs-keyword">from</span> <span class="hljs-string">'node:process'</span>;
process.<span class="hljs-title function_">on</span>(<span class="hljs-string">'multipleResolves'</span>, <span class="hljs-function">(<span class="hljs-params">type, promise, reason</span>) =></span> {
<span class="hljs-variable language_">console</span>.<span class="hljs-title function_">error</span>(type, promise, reason);
<span class="hljs-title function_">setImmediate</span>(<span class="hljs-function">() =></span> process.<span class="hljs-title function_">exit</span>(<span class="hljs-number">1</span>));
});
<span class="hljs-keyword">async</span> <span class="hljs-keyword">function</span> <span class="hljs-title function_">main</span>(<span class="hljs-params"></span>) {
<span class="hljs-keyword">try</span> {
<span class="hljs-keyword">return</span> <span class="hljs-keyword">await</span> <span class="hljs-keyword">new</span> <span class="hljs-title class_">Promise</span>(<span class="hljs-function">(<span class="hljs-params">resolve, reject</span>) =></span> {
<span class="hljs-title function_">resolve</span>(<span class="hljs-string">'First call'</span>);
<span class="hljs-title function_">resolve</span>(<span class="hljs-string">'Swallowed resolve'</span>);
<span class="hljs-title function_">reject</span>(<span class="hljs-keyword">new</span> <span class="hljs-title class_">Error</span>(<span class="hljs-string">'Swallowed reject'</span>));
});
} <span class="hljs-keyword">catch</span> {
<span class="hljs-keyword">throw</span> <span class="hljs-keyword">new</span> <span class="hljs-title class_">Error</span>(<span class="hljs-string">'Failed'</span>);
}
}
<span class="hljs-title function_">main</span>().<span class="hljs-title function_">then</span>(<span class="hljs-variable language_">console</span>.<span class="hljs-property">log</span>);
<span class="hljs-comment">// resolve: Promise { 'First call' } 'Swallowed resolve'</span>
<span class="hljs-comment">// reject: Promise { 'First call' } Error: Swallowed reject</span>
<span class="hljs-comment">// at Promise (*)</span>
<span class="hljs-comment">// at new Promise (<anonymous>)</span>
<span class="hljs-comment">// at main (*)</span>
<span class="hljs-comment">// First call</span></code><code class="language-js cjs"><span class="hljs-keyword">const</span> process = <span class="hljs-built_in">require</span>(<span class="hljs-string">'node:process'</span>);
process.<span class="hljs-title function_">on</span>(<span class="hljs-string">'multipleResolves'</span>, <span class="hljs-function">(<span class="hljs-params">type, promise, reason</span>) =></span> {
<span class="hljs-variable language_">console</span>.<span class="hljs-title function_">error</span>(type, promise, reason);
<span class="hljs-title function_">setImmediate</span>(<span class="hljs-function">() =></span> process.<span class="hljs-title function_">exit</span>(<span class="hljs-number">1</span>));
});
<span class="hljs-keyword">async</span> <span class="hljs-keyword">function</span> <span class="hljs-title function_">main</span>(<span class="hljs-params"></span>) {
<span class="hljs-keyword">try</span> {
<span class="hljs-keyword">return</span> <span class="hljs-keyword">await</span> <span class="hljs-keyword">new</span> <span class="hljs-title class_">Promise</span>(<span class="hljs-function">(<span class="hljs-params">resolve, reject</span>) =></span> {
<span class="hljs-title function_">resolve</span>(<span class="hljs-string">'First call'</span>);
<span class="hljs-title function_">resolve</span>(<span class="hljs-string">'Swallowed resolve'</span>);
<span class="hljs-title function_">reject</span>(<span class="hljs-keyword">new</span> <span class="hljs-title class_">Error</span>(<span class="hljs-string">'Swallowed reject'</span>));
});
} <span class="hljs-keyword">catch</span> {
<span class="hljs-keyword">throw</span> <span class="hljs-keyword">new</span> <span class="hljs-title class_">Error</span>(<span class="hljs-string">'Failed'</span>);
}
}
<span class="hljs-title function_">main</span>().<span class="hljs-title function_">then</span>(<span class="hljs-variable language_">console</span>.<span class="hljs-property">log</span>);
<span class="hljs-comment">// resolve: Promise { 'First call' } 'Swallowed resolve'</span>
<span class="hljs-comment">// reject: Promise { 'First call' } Error: Swallowed reject</span>
<span class="hljs-comment">// at Promise (*)</span>
<span class="hljs-comment">// at new Promise (<anonymous>)</span>
<span class="hljs-comment">// at main (*)</span>
<span class="hljs-comment">// First call</span></code><button class="copy-button">copy</button></pre>
<h4>Event: <code>'rejectionHandled'</code><span><a class="mark" href="#event-rejectionhandled" id="event-rejectionhandled">#</a></span><a aria-hidden="true" class="legacy" id="process_event_rejectionhandled"></a></h4>
<div class="api_metadata">
<span>Added in: v1.4.1</span>
</div>
<ul>
<li><code>promise</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise" class="type"><Promise></a> The late handled promise.</li>
</ul>
<p>The <code>'rejectionHandled'</code> event is emitted whenever a <code>Promise</code> has been rejected
and an error handler was attached to it (using <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise/catch"><code>promise.catch()</code></a>, for
example) later than one turn of the Node.js event loop.</p>
<p>The <code>Promise</code> object would have previously been emitted in an
<code>'unhandledRejection'</code> event, but during the course of processing gained a
rejection handler.</p>
<p>There is no notion of a top level for a <code>Promise</code> chain at which rejections can
always be handled. Being inherently asynchronous in nature, a <code>Promise</code>
rejection can be handled at a future point in time, possibly much later than
the event loop turn it takes for the <code>'unhandledRejection'</code> event to be emitted.</p>
<p>Another way of stating this is that, unlike in synchronous code where there is
an ever-growing list of unhandled exceptions, with Promises there can be a
growing-and-shrinking list of unhandled rejections.</p>
<p>In synchronous code, the <code>'uncaughtException'</code> event is emitted when the list of
unhandled exceptions grows.</p>
<p>In asynchronous code, the <code>'unhandledRejection'</code> event is emitted when the list
of unhandled rejections grows, and the <code>'rejectionHandled'</code> event is emitted
when the list of unhandled rejections shrinks.</p>
<pre class="with-40-chars"><input class="js-flavor-toggle" type="checkbox" checked aria-label="Show modern ES modules syntax"><code class="language-js mjs"><span class="hljs-keyword">import</span> process <span class="hljs-keyword">from</span> <span class="hljs-string">'node:process'</span>;
<span class="hljs-keyword">const</span> unhandledRejections = <span class="hljs-keyword">new</span> <span class="hljs-title class_">Map</span>();
process.<span class="hljs-title function_">on</span>(<span class="hljs-string">'unhandledRejection'</span>, <span class="hljs-function">(<span class="hljs-params">reason, promise</span>) =></span> {
unhandledRejections.<span class="hljs-title function_">set</span>(promise, reason);
});
process.<span class="hljs-title function_">on</span>(<span class="hljs-string">'rejectionHandled'</span>, <span class="hljs-function">(<span class="hljs-params">promise</span>) =></span> {
unhandledRejections.<span class="hljs-title function_">delete</span>(promise);
});</code><code class="language-js cjs"><span class="hljs-keyword">const</span> process = <span class="hljs-built_in">require</span>(<span class="hljs-string">'node:process'</span>);
<span class="hljs-keyword">const</span> unhandledRejections = <span class="hljs-keyword">new</span> <span class="hljs-title class_">Map</span>();
process.<span class="hljs-title function_">on</span>(<span class="hljs-string">'unhandledRejection'</span>, <span class="hljs-function">(<span class="hljs-params">reason, promise</span>) =></span> {
unhandledRejections.<span class="hljs-title function_">set</span>(promise, reason);
});
process.<span class="hljs-title function_">on</span>(<span class="hljs-string">'rejectionHandled'</span>, <span class="hljs-function">(<span class="hljs-params">promise</span>) =></span> {
unhandledRejections.<span class="hljs-title function_">delete</span>(promise);
});</code><button class="copy-button">copy</button></pre>
<p>In this example, the <code>unhandledRejections</code> <code>Map</code> will grow and shrink over time,
reflecting rejections that start unhandled and then become handled. It is
possible to record such errors in an error log, either periodically (which is
likely best for long-running application) or upon process exit (which is likely
most convenient for scripts).</p>
<h4>Event: <code>'workerMessage'</code><span><a class="mark" href="#event-workermessage" id="event-workermessage">#</a></span><a aria-hidden="true" class="legacy" id="process_event_workermessage"></a></h4>
<div class="api_metadata">
<span>Added in: v22.5.0</span>
</div>
<ul>
<li><code>value</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Data_types" class="type"><any></a> A value transmitted using <a href="worker_threads.html#workerpostmessagetothreadthreadid-value-transferlist-timeout"><code>postMessageToThread()</code></a>.</li>
<li><code>source</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type" class="type"><number></a> The transmitting worker thread ID or <code>0</code>Â for the main thread.</li>
</ul>
<p>The <code>'workerMessage'</code> event is emitted for any incoming message send by the other
party by using <a href="worker_threads.html#workerpostmessagetothreadthreadid-value-transferlist-timeout"><code>postMessageToThread()</code></a>.</p>
<h4>Event: <code>'uncaughtException'</code><span><a class="mark" href="#event-uncaughtexception" id="event-uncaughtexception">#</a></span><a aria-hidden="true" class="legacy" id="process_event_uncaughtexception"></a></h4>
<div class="api_metadata">
<details class="changelog"><summary>History</summary>
<table>
<tbody><tr><th>Version</th><th>Changes</th></tr>
<tr><td>v12.0.0, v10.17.0</td>
<td><p>Added the <code>origin</code> argument.</p></td></tr>
<tr><td>v0.1.18</td>
<td><p><span>Added in: v0.1.18</span></p></td></tr>
</tbody></table>
</details>
</div>
<ul>
<li><code>err</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Error" class="type"><Error></a> The uncaught exception.</li>
<li><code>origin</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type"><string></a> Indicates if the exception originates from an unhandled
rejection or from a synchronous error. Can either be <code>'uncaughtException'</code> or
<code>'unhandledRejection'</code>. The latter is used when an exception happens in a
<code>Promise</code> based async context (or if a <code>Promise</code> is rejected) and
<a href="cli.html#--unhandled-rejectionsmode"><code>--unhandled-rejections</code></a> flag set to <code>strict</code> or <code>throw</code> (which is the
default) and the rejection is not handled, or when a rejection happens during
the command line entry point's ES module static loading phase.</li>
</ul>
<p>The <code>'uncaughtException'</code> event is emitted when an uncaught JavaScript
exception bubbles all the way back to the event loop. By default, Node.js
handles such exceptions by printing the stack trace to <code>stderr</code> and exiting
with code 1, overriding any previously set <a href="#processexitcode_1"><code>process.exitCode</code></a>.
Adding a handler for the <code>'uncaughtException'</code> event overrides this default
behavior. Alternatively, change the <a href="#processexitcode_1"><code>process.exitCode</code></a> in the
<code>'uncaughtException'</code> handler which will result in the process exiting with the
provided exit code. Otherwise, in the presence of such handler the process will
exit with 0.</p>
<pre class="with-40-chars"><input class="js-flavor-toggle" type="checkbox" checked aria-label="Show modern ES modules syntax"><code class="language-js mjs"><span class="hljs-keyword">import</span> process <span class="hljs-keyword">from</span> <span class="hljs-string">'node:process'</span>;
<span class="hljs-keyword">import</span> fs <span class="hljs-keyword">from</span> <span class="hljs-string">'node:fs'</span>;
process.<span class="hljs-title function_">on</span>(<span class="hljs-string">'uncaughtException'</span>, <span class="hljs-function">(<span class="hljs-params">err, origin</span>) =></span> {
fs.<span class="hljs-title function_">writeSync</span>(
process.<span class="hljs-property">stderr</span>.<span class="hljs-property">fd</span>,
<span class="hljs-string">`Caught exception: <span class="hljs-subst">${err}</span>\n`</span> +
<span class="hljs-string">`Exception origin: <span class="hljs-subst">${origin}</span>\n`</span>,
);
});
<span class="hljs-built_in">setTimeout</span>(<span class="hljs-function">() =></span> {
<span class="hljs-variable language_">console</span>.<span class="hljs-title function_">log</span>(<span class="hljs-string">'This will still run.'</span>);
}, <span class="hljs-number">500</span>);
<span class="hljs-comment">// Intentionally cause an exception, but don't catch it.</span>
<span class="hljs-title function_">nonexistentFunc</span>();
<span class="hljs-variable language_">console</span>.<span class="hljs-title function_">log</span>(<span class="hljs-string">'This will not run.'</span>);</code><code class="language-js cjs"><span class="hljs-keyword">const</span> process = <span class="hljs-built_in">require</span>(<span class="hljs-string">'node:process'</span>);
<span class="hljs-keyword">const</span> fs = <span class="hljs-built_in">require</span>(<span class="hljs-string">'node:fs'</span>);
process.<span class="hljs-title function_">on</span>(<span class="hljs-string">'uncaughtException'</span>, <span class="hljs-function">(<span class="hljs-params">err, origin</span>) =></span> {
fs.<span class="hljs-title function_">writeSync</span>(
process.<span class="hljs-property">stderr</span>.<span class="hljs-property">fd</span>,
<span class="hljs-string">`Caught exception: <span class="hljs-subst">${err}</span>\n`</span> +
<span class="hljs-string">`Exception origin: <span class="hljs-subst">${origin}</span>\n`</span>,
);
});
<span class="hljs-built_in">setTimeout</span>(<span class="hljs-function">() =></span> {
<span class="hljs-variable language_">console</span>.<span class="hljs-title function_">log</span>(<span class="hljs-string">'This will still run.'</span>);
}, <span class="hljs-number">500</span>);
<span class="hljs-comment">// Intentionally cause an exception, but don't catch it.</span>
<span class="hljs-title function_">nonexistentFunc</span>();
<span class="hljs-variable language_">console</span>.<span class="hljs-title function_">log</span>(<span class="hljs-string">'This will not run.'</span>);</code><button class="copy-button">copy</button></pre>
<p>It is possible to monitor <code>'uncaughtException'</code> events without overriding the
default behavior to exit the process by installing a
<code>'uncaughtExceptionMonitor'</code> listener.</p>
<h5>Warning: Using <code>'uncaughtException'</code> correctly<span><a class="mark" href="#warning-using-uncaughtexception-correctly" id="warning-using-uncaughtexception-correctly">#</a></span><a aria-hidden="true" class="legacy" id="process_warning_using_uncaughtexception_correctly"></a></h5>
<p><code>'uncaughtException'</code> is a crude mechanism for exception handling
intended to be used only as a last resort. The event <em>should not</em> be used as
an equivalent to <code>On Error Resume Next</code>. Unhandled exceptions inherently mean
that an application is in an undefined state. Attempting to resume application
code without properly recovering from the exception can cause additional
unforeseen and unpredictable issues.</p>
<p>Exceptions thrown from within the event handler will not be caught. Instead the
process will exit with a non-zero exit code and the stack trace will be printed.
This is to avoid infinite recursion.</p>
<p>Attempting to resume normally after an uncaught exception can be similar to
pulling out the power cord when upgrading a computer. Nine out of ten
times, nothing happens. But the tenth time, the system becomes corrupted.</p>
<p>The correct use of <code>'uncaughtException'</code> is to perform synchronous cleanup
of allocated resources (e.g. file descriptors, handles, etc) before shutting
down the process. <strong>It is not safe to resume normal operation after
<code>'uncaughtException'</code>.</strong></p>
<p>To restart a crashed application in a more reliable way, whether
<code>'uncaughtException'</code> is emitted or not, an external monitor should be employed
in a separate process to detect application failures and recover or restart as
needed.</p>
<h4>Event: <code>'uncaughtExceptionMonitor'</code><span><a class="mark" href="#event-uncaughtexceptionmonitor" id="event-uncaughtexceptionmonitor">#</a></span><a aria-hidden="true" class="legacy" id="process_event_uncaughtexceptionmonitor"></a></h4>
<div class="api_metadata">
<span>Added in: v13.7.0, v12.17.0</span>
</div>
<ul>
<li><code>err</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Error" class="type"><Error></a> The uncaught exception.</li>
<li><code>origin</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type"><string></a> Indicates if the exception originates from an unhandled
rejection or from synchronous errors. Can either be <code>'uncaughtException'</code> or
<code>'unhandledRejection'</code>. The latter is used when an exception happens in a
<code>Promise</code> based async context (or if a <code>Promise</code> is rejected) and
<a href="cli.html#--unhandled-rejectionsmode"><code>--unhandled-rejections</code></a> flag set to <code>strict</code> or <code>throw</code> (which is the
default) and the rejection is not handled, or when a rejection happens during
the command line entry point's ES module static loading phase.</li>
</ul>
<p>The <code>'uncaughtExceptionMonitor'</code> event is emitted before an
<code>'uncaughtException'</code> event is emitted or a hook installed via
<a href="#processsetuncaughtexceptioncapturecallbackfn"><code>process.setUncaughtExceptionCaptureCallback()</code></a> is called.</p>
<p>Installing an <code>'uncaughtExceptionMonitor'</code> listener does not change the behavior
once an <code>'uncaughtException'</code> event is emitted. The process will
still crash if no <code>'uncaughtException'</code> listener is installed.</p>
<pre class="with-40-chars"><input class="js-flavor-toggle" type="checkbox" checked aria-label="Show modern ES modules syntax"><code class="language-js mjs"><span class="hljs-keyword">import</span> process <span class="hljs-keyword">from</span> <span class="hljs-string">'node:process'</span>;
process.<span class="hljs-title function_">on</span>(<span class="hljs-string">'uncaughtExceptionMonitor'</span>, <span class="hljs-function">(<span class="hljs-params">err, origin</span>) =></span> {
<span class="hljs-title class_">MyMonitoringTool</span>.<span class="hljs-title function_">logSync</span>(err, origin);
});
<span class="hljs-comment">// Intentionally cause an exception, but don't catch it.</span>
<span class="hljs-title function_">nonexistentFunc</span>();
<span class="hljs-comment">// Still crashes Node.js</span></code><code class="language-js cjs"><span class="hljs-keyword">const</span> process = <span class="hljs-built_in">require</span>(<span class="hljs-string">'node:process'</span>);
process.<span class="hljs-title function_">on</span>(<span class="hljs-string">'uncaughtExceptionMonitor'</span>, <span class="hljs-function">(<span class="hljs-params">err, origin</span>) =></span> {
<span class="hljs-title class_">MyMonitoringTool</span>.<span class="hljs-title function_">logSync</span>(err, origin);
});
<span class="hljs-comment">// Intentionally cause an exception, but don't catch it.</span>
<span class="hljs-title function_">nonexistentFunc</span>();
<span class="hljs-comment">// Still crashes Node.js</span></code><button class="copy-button">copy</button></pre>
<h4>Event: <code>'unhandledRejection'</code><span><a class="mark" href="#event-unhandledrejection" id="event-unhandledrejection">#</a></span><a aria-hidden="true" class="legacy" id="process_event_unhandledrejection"></a></h4>
<div class="api_metadata">
<details class="changelog"><summary>History</summary>
<table>
<tbody><tr><th>Version</th><th>Changes</th></tr>
<tr><td>v7.0.0</td>
<td><p>Not handling <code>Promise</code> rejections is deprecated.</p></td></tr>
<tr><td>v6.6.0</td>
<td><p>Unhandled <code>Promise</code> rejections will now emit a process warning.</p></td></tr>
<tr><td>v1.4.1</td>
<td><p><span>Added in: v1.4.1</span></p></td></tr>
</tbody></table>
</details>
</div>
<ul>
<li><code>reason</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Error" class="type"><Error></a> | <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Data_types" class="type"><any></a> The object with which the promise was rejected
(typically an <a href="errors.html#class-error"><code>Error</code></a> object).</li>
<li><code>promise</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise" class="type"><Promise></a> The rejected promise.</li>
</ul>
<p>The <code>'unhandledRejection'</code> event is emitted whenever a <code>Promise</code> is rejected and
no error handler is attached to the promise within a turn of the event loop.
When programming with Promises, exceptions are encapsulated as "rejected
promises". Rejections can be caught and handled using <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise/catch"><code>promise.catch()</code></a> and
are propagated through a <code>Promise</code> chain. The <code>'unhandledRejection'</code> event is
useful for detecting and keeping track of promises that were rejected whose
rejections have not yet been handled.</p>
<pre class="with-40-chars"><input class="js-flavor-toggle" type="checkbox" checked aria-label="Show modern ES modules syntax"><code class="language-js mjs"><span class="hljs-keyword">import</span> process <span class="hljs-keyword">from</span> <span class="hljs-string">'node:process'</span>;
process.<span class="hljs-title function_">on</span>(<span class="hljs-string">'unhandledRejection'</span>, <span class="hljs-function">(<span class="hljs-params">reason, promise</span>) =></span> {
<span class="hljs-variable language_">console</span>.<span class="hljs-title function_">log</span>(<span class="hljs-string">'Unhandled Rejection at:'</span>, promise, <span class="hljs-string">'reason:'</span>, reason);
<span class="hljs-comment">// Application specific logging, throwing an error, or other logic here</span>
});
somePromise.<span class="hljs-title function_">then</span>(<span class="hljs-function">(<span class="hljs-params">res</span>) =></span> {
<span class="hljs-keyword">return</span> <span class="hljs-title function_">reportToUser</span>(<span class="hljs-title class_">JSON</span>.<span class="hljs-title function_">pasre</span>(res)); <span class="hljs-comment">// Note the typo (`pasre`)</span>
}); <span class="hljs-comment">// No `.catch()` or `.then()`</span></code><code class="language-js cjs"><span class="hljs-keyword">const</span> process = <span class="hljs-built_in">require</span>(<span class="hljs-string">'node:process'</span>);
process.<span class="hljs-title function_">on</span>(<span class="hljs-string">'unhandledRejection'</span>, <span class="hljs-function">(<span class="hljs-params">reason, promise</span>) =></span> {
<span class="hljs-variable language_">console</span>.<span class="hljs-title function_">log</span>(<span class="hljs-string">'Unhandled Rejection at:'</span>, promise, <span class="hljs-string">'reason:'</span>, reason);
<span class="hljs-comment">// Application specific logging, throwing an error, or other logic here</span>
});
somePromise.<span class="hljs-title function_">then</span>(<span class="hljs-function">(<span class="hljs-params">res</span>) =></span> {
<span class="hljs-keyword">return</span> <span class="hljs-title function_">reportToUser</span>(<span class="hljs-title class_">JSON</span>.<span class="hljs-title function_">pasre</span>(res)); <span class="hljs-comment">// Note the typo (`pasre`)</span>
}); <span class="hljs-comment">// No `.catch()` or `.then()`</span></code><button class="copy-button">copy</button></pre>
<p>The following will also trigger the <code>'unhandledRejection'</code> event to be
emitted:</p>
<pre class="with-40-chars"><input class="js-flavor-toggle" type="checkbox" checked aria-label="Show modern ES modules syntax"><code class="language-js mjs"><span class="hljs-keyword">import</span> process <span class="hljs-keyword">from</span> <span class="hljs-string">'node:process'</span>;
<span class="hljs-keyword">function</span> <span class="hljs-title function_">SomeResource</span>(<span class="hljs-params"></span>) {
<span class="hljs-comment">// Initially set the loaded status to a rejected promise</span>
<span class="hljs-variable language_">this</span>.<span class="hljs-property">loaded</span> = <span class="hljs-title class_">Promise</span>.<span class="hljs-title function_">reject</span>(<span class="hljs-keyword">new</span> <span class="hljs-title class_">Error</span>(<span class="hljs-string">'Resource not yet loaded!'</span>));
}
<span class="hljs-keyword">const</span> resource = <span class="hljs-keyword">new</span> <span class="hljs-title class_">SomeResource</span>();
<span class="hljs-comment">// no .catch or .then on resource.loaded for at least a turn</span></code><code class="language-js cjs"><span class="hljs-keyword">const</span> process = <span class="hljs-built_in">require</span>(<span class="hljs-string">'node:process'</span>);
<span class="hljs-keyword">function</span> <span class="hljs-title function_">SomeResource</span>(<span class="hljs-params"></span>) {
<span class="hljs-comment">// Initially set the loaded status to a rejected promise</span>
<span class="hljs-variable language_">this</span>.<span class="hljs-property">loaded</span> = <span class="hljs-title class_">Promise</span>.<span class="hljs-title function_">reject</span>(<span class="hljs-keyword">new</span> <span class="hljs-title class_">Error</span>(<span class="hljs-string">'Resource not yet loaded!'</span>));
}
<span class="hljs-keyword">const</span> resource = <span class="hljs-keyword">new</span> <span class="hljs-title class_">SomeResource</span>();
<span class="hljs-comment">// no .catch or .then on resource.loaded for at least a turn</span></code><button class="copy-button">copy</button></pre>
<p>In this example case, it is possible to track the rejection as a developer error
as would typically be the case for other <code>'unhandledRejection'</code> events. To
address such failures, a non-operational
<a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise/catch"><code>.catch(() => { })</code></a> handler may be attached to
<code>resource.loaded</code>, which would prevent the <code>'unhandledRejection'</code> event from
being emitted.</p>
<h4>Event: <code>'warning'</code><span><a class="mark" href="#event-warning" id="event-warning">#</a></span><a aria-hidden="true" class="legacy" id="process_event_warning"></a></h4>
<div class="api_metadata">
<span>Added in: v6.0.0</span>
</div>
<ul>
<li><code>warning</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Error" class="type"><Error></a> Key properties of the warning are:
<ul>
<li><code>name</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type"><string></a> The name of the warning. <strong>Default:</strong> <code>'Warning'</code>.</li>
<li><code>message</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type"><string></a> A system-provided description of the warning.</li>
<li><code>stack</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type"><string></a> A stack trace to the location in the code where the warning
was issued.</li>
</ul>
</li>
</ul>
<p>The <code>'warning'</code> event is emitted whenever Node.js emits a process warning.</p>
<p>A process warning is similar to an error in that it describes exceptional
conditions that are being brought to the user's attention. However, warnings
are not part of the normal Node.js and JavaScript error handling flow.
Node.js can emit warnings whenever it detects bad coding practices that could
lead to sub-optimal application performance, bugs, or security vulnerabilities.</p>
<pre class="with-40-chars"><input class="js-flavor-toggle" type="checkbox" checked aria-label="Show modern ES modules syntax"><code class="language-js mjs"><span class="hljs-keyword">import</span> process <span class="hljs-keyword">from</span> <span class="hljs-string">'node:process'</span>;
process.<span class="hljs-title function_">on</span>(<span class="hljs-string">'warning'</span>, <span class="hljs-function">(<span class="hljs-params">warning</span>) =></span> {
<span class="hljs-variable language_">console</span>.<span class="hljs-title function_">warn</span>(warning.<span class="hljs-property">name</span>); <span class="hljs-comment">// Print the warning name</span>
<span class="hljs-variable language_">console</span>.<span class="hljs-title function_">warn</span>(warning.<span class="hljs-property">message</span>); <span class="hljs-comment">// Print the warning message</span>
<span class="hljs-variable language_">console</span>.<span class="hljs-title function_">warn</span>(warning.<span class="hljs-property">stack</span>); <span class="hljs-comment">// Print the stack trace</span>
});</code><code class="language-js cjs"><span class="hljs-keyword">const</span> process = <span class="hljs-built_in">require</span>(<span class="hljs-string">'node:process'</span>);
process.<span class="hljs-title function_">on</span>(<span class="hljs-string">'warning'</span>, <span class="hljs-function">(<span class="hljs-params">warning</span>) =></span> {
<span class="hljs-variable language_">console</span>.<span class="hljs-title function_">warn</span>(warning.<span class="hljs-property">name</span>); <span class="hljs-comment">// Print the warning name</span>
<span class="hljs-variable language_">console</span>.<span class="hljs-title function_">warn</span>(warning.<span class="hljs-property">message</span>); <span class="hljs-comment">// Print the warning message</span>
<span class="hljs-variable language_">console</span>.<span class="hljs-title function_">warn</span>(warning.<span class="hljs-property">stack</span>); <span class="hljs-comment">// Print the stack trace</span>
});</code><button class="copy-button">copy</button></pre>
<p>By default, Node.js will print process warnings to <code>stderr</code>. The <code>--no-warnings</code>
command-line option can be used to suppress the default console output but the
<code>'warning'</code> event will still be emitted by the <code>process</code> object. Currently, it
is not possible to suppress specific warning types other than deprecation
warnings. To suppress deprecation warnings, check out the <a href="cli.html#--no-deprecation"><code>--no-deprecation</code></a>
flag.</p>
<p>The following example illustrates the warning that is printed to <code>stderr</code> when
too many listeners have been added to an event:</p>
<pre><code class="language-console"><span class="hljs-meta prompt_">$ </span><span class="language-bash">node</span>
<span class="hljs-meta prompt_">> </span><span class="language-bash">events.defaultMaxListeners = 1;</span>
<span class="hljs-meta prompt_">> </span><span class="language-bash">process.on(<span class="hljs-string">'foo'</span>, () => {});</span>
<span class="hljs-meta prompt_">> </span><span class="language-bash">process.on(<span class="hljs-string">'foo'</span>, () => {});</span>
<span class="hljs-meta prompt_">> </span><span class="language-bash">(node:38638) MaxListenersExceededWarning: Possible EventEmitter memory leak</span>
detected. 2 foo listeners added. Use emitter.setMaxListeners() to increase limit</code> <button class="copy-button">copy</button></pre>
<p>In contrast, the following example turns off the default warning output and
adds a custom handler to the <code>'warning'</code> event:</p>
<pre><code class="language-console"><span class="hljs-meta prompt_">$ </span><span class="language-bash">node --no-warnings</span>
<span class="hljs-meta prompt_">> </span><span class="language-bash">const p = process.on(<span class="hljs-string">'warning'</span>, (warning) => console.warn(<span class="hljs-string">'Do not do that!'</span>));</span>
<span class="hljs-meta prompt_">> </span><span class="language-bash">events.defaultMaxListeners = 1;</span>
<span class="hljs-meta prompt_">> </span><span class="language-bash">process.on(<span class="hljs-string">'foo'</span>, () => {});</span>
<span class="hljs-meta prompt_">> </span><span class="language-bash">process.on(<span class="hljs-string">'foo'</span>, () => {});</span>
<span class="hljs-meta prompt_">> </span><span class="language-bash">Do not <span class="hljs-keyword">do</span> that!</span></code> <button class="copy-button">copy</button></pre>
<p>The <code>--trace-warnings</code> command-line option can be used to have the default
console output for warnings include the full stack trace of the warning.</p>
<p>Launching Node.js using the <code>--throw-deprecation</code> command-line flag will
cause custom deprecation warnings to be thrown as exceptions.</p>
<p>Using the <code>--trace-deprecation</code> command-line flag will cause the custom
deprecation to be printed to <code>stderr</code> along with the stack trace.</p>
<p>Using the <code>--no-deprecation</code> command-line flag will suppress all reporting
of the custom deprecation.</p>
<p>The <code>*-deprecation</code> command-line flags only affect warnings that use the name
<code>'DeprecationWarning'</code>.</p>
<h5>Emitting custom warnings<span><a class="mark" href="#emitting-custom-warnings" id="emitting-custom-warnings">#</a></span><a aria-hidden="true" class="legacy" id="process_emitting_custom_warnings"></a></h5>
<p>See the <a href="#processemitwarningwarning-type-code-ctor"><code>process.emitWarning()</code></a> method for issuing
custom or application-specific warnings.</p>
<h5>Node.js warning names<span><a class="mark" href="#nodejs-warning-names" id="nodejs-warning-names">#</a></span><a aria-hidden="true" class="legacy" id="process_node_js_warning_names"></a></h5>
<p>There are no strict guidelines for warning types (as identified by the <code>name</code>
property) emitted by Node.js. New types of warnings can be added at any time.
A few of the warning types that are most common include:</p>
<ul>
<li><code>'DeprecationWarning'</code> - Indicates use of a deprecated Node.js API or feature.
Such warnings must include a <code>'code'</code> property identifying the
<a href="deprecations.html">deprecation code</a>.</li>
<li><code>'ExperimentalWarning'</code> - Indicates use of an experimental Node.js API or
feature. Such features must be used with caution as they may change at any
time and are not subject to the same strict semantic-versioning and long-term
support policies as supported features.</li>
<li><code>'MaxListenersExceededWarning'</code> - Indicates that too many listeners for a
given event have been registered on either an <code>EventEmitter</code> or <code>EventTarget</code>.
This is often an indication of a memory leak.</li>
<li><code>'TimeoutOverflowWarning'</code> - Indicates that a numeric value that cannot fit
within a 32-bit signed integer has been provided to either the <code>setTimeout()</code>
or <code>setInterval()</code> functions.</li>
<li><code>'UnsupportedWarning'</code> - Indicates use of an unsupported option or feature
that will be ignored rather than treated as an error. One example is use of
the HTTP response status message when using the HTTP/2 compatibility API.</li>
</ul>
<h4>Event: <code>'worker'</code><span><a class="mark" href="#event-worker" id="event-worker">#</a></span><a aria-hidden="true" class="legacy" id="process_event_worker"></a></h4>
<div class="api_metadata">
<span>Added in: v16.2.0, v14.18.0</span>
</div>
<ul>
<li><code>worker</code> <a href="worker_threads.html#class-worker" class="type"><Worker></a> The <a href="worker_threads.html#class-worker" class="type"><Worker></a> that was created.</li>
</ul>
<p>The <code>'worker'</code> event is emitted after a new <a href="worker_threads.html#class-worker" class="type"><Worker></a> thread has been created.</p>
<h4>Signal events<span><a class="mark" href="#signal-events" id="signal-events">#</a></span><a aria-hidden="true" class="legacy" id="process_signal_events"></a></h4>
<p>Signal events will be emitted when the Node.js process receives a signal. Please
refer to <a href="http://man7.org/linux/man-pages/man7/signal.7.html"><code>signal(7)</code></a> for a listing of standard POSIX signal names such as
<code>'SIGINT'</code>, <code>'SIGHUP'</code>, etc.</p>
<p>Signals are not available on <a href="worker_threads.html#class-worker"><code>Worker</code></a> threads.</p>
<p>The signal handler will receive the signal's name (<code>'SIGINT'</code>,
<code>'SIGTERM'</code>, etc.) as the first argument.</p>
<p>The name of each event will be the uppercase common name for the signal (e.g.
<code>'SIGINT'</code> for <code>SIGINT</code> signals).</p>
<pre class="with-40-chars"><input class="js-flavor-toggle" type="checkbox" checked aria-label="Show modern ES modules syntax"><code class="language-js mjs"><span class="hljs-keyword">import</span> process <span class="hljs-keyword">from</span> <span class="hljs-string">'node:process'</span>;
<span class="hljs-comment">// Begin reading from stdin so the process does not exit.</span>
process.<span class="hljs-property">stdin</span>.<span class="hljs-title function_">resume</span>();
process.<span class="hljs-title function_">on</span>(<span class="hljs-string">'SIGINT'</span>, <span class="hljs-function">() =></span> {
<span class="hljs-variable language_">console</span>.<span class="hljs-title function_">log</span>(<span class="hljs-string">'Received SIGINT. Press Control-D to exit.'</span>);
});
<span class="hljs-comment">// Using a single function to handle multiple signals</span>
<span class="hljs-keyword">function</span> <span class="hljs-title function_">handle</span>(<span class="hljs-params">signal</span>) {
<span class="hljs-variable language_">console</span>.<span class="hljs-title function_">log</span>(<span class="hljs-string">`Received <span class="hljs-subst">${signal}</span>`</span>);
}
process.<span class="hljs-title function_">on</span>(<span class="hljs-string">'SIGINT'</span>, handle);
process.<span class="hljs-title function_">on</span>(<span class="hljs-string">'SIGTERM'</span>, handle);</code><code class="language-js cjs"><span class="hljs-keyword">const</span> process = <span class="hljs-built_in">require</span>(<span class="hljs-string">'node:process'</span>);
<span class="hljs-comment">// Begin reading from stdin so the process does not exit.</span>
process.<span class="hljs-property">stdin</span>.<span class="hljs-title function_">resume</span>();
process.<span class="hljs-title function_">on</span>(<span class="hljs-string">'SIGINT'</span>, <span class="hljs-function">() =></span> {
<span class="hljs-variable language_">console</span>.<span class="hljs-title function_">log</span>(<span class="hljs-string">'Received SIGINT. Press Control-D to exit.'</span>);
});
<span class="hljs-comment">// Using a single function to handle multiple signals</span>
<span class="hljs-keyword">function</span> <span class="hljs-title function_">handle</span>(<span class="hljs-params">signal</span>) {
<span class="hljs-variable language_">console</span>.<span class="hljs-title function_">log</span>(<span class="hljs-string">`Received <span class="hljs-subst">${signal}</span>`</span>);
}
process.<span class="hljs-title function_">on</span>(<span class="hljs-string">'SIGINT'</span>, handle);
process.<span class="hljs-title function_">on</span>(<span class="hljs-string">'SIGTERM'</span>, handle);</code><button class="copy-button">copy</button></pre>
<ul>
<li><code>'SIGUSR1'</code> is reserved by Node.js to start the <a href="debugger.html">debugger</a>. It's possible to
install a listener but doing so might interfere with the debugger.</li>
<li><code>'SIGTERM'</code> and <code>'SIGINT'</code> have default handlers on non-Windows platforms that
reset the terminal mode before exiting with code <code>128 + signal number</code>. If one
of these signals has a listener installed, its default behavior will be
removed (Node.js will no longer exit).</li>
<li><code>'SIGPIPE'</code> is ignored by default. It can have a listener installed.</li>
<li><code>'SIGHUP'</code> is generated on Windows when the console window is closed, and on
other platforms under various similar conditions. See <a href="http://man7.org/linux/man-pages/man7/signal.7.html"><code>signal(7)</code></a>. It can have a
listener installed, however Node.js will be unconditionally terminated by
Windows about 10 seconds later. On non-Windows platforms, the default
behavior of <code>SIGHUP</code> is to terminate Node.js, but once a listener has been
installed its default behavior will be removed.</li>
<li><code>'SIGTERM'</code> is not supported on Windows, it can be listened on.</li>
<li><code>'SIGINT'</code> from the terminal is supported on all platforms, and can usually be
generated with <kbd>Ctrl</kbd>+<kbd>C</kbd> (though this may be configurable).
It is not generated when <a href="tty.html#readstreamsetrawmodemode">terminal raw mode</a> is enabled
and <kbd>Ctrl</kbd>+<kbd>C</kbd> is used.</li>
<li><code>'SIGBREAK'</code> is delivered on Windows when <kbd>Ctrl</kbd>+<kbd>Break</kbd> is
pressed. On non-Windows platforms, it can be listened on, but there is no way
to send or generate it.</li>
<li><code>'SIGWINCH'</code> is delivered when the console has been resized. On Windows, this
will only happen on write to the console when the cursor is being moved, or
when a readable tty is used in raw mode.</li>
<li><code>'SIGKILL'</code> cannot have a listener installed, it will unconditionally
terminate Node.js on all platforms.</li>
<li><code>'SIGSTOP'</code> cannot have a listener installed.</li>
<li><code>'SIGBUS'</code>, <code>'SIGFPE'</code>, <code>'SIGSEGV'</code>, and <code>'SIGILL'</code>, when not raised
artificially using <a href="http://man7.org/linux/man-pages/man2/kill.2.html"><code>kill(2)</code></a>, inherently leave the process in a state from
which it is not safe to call JS listeners. Doing so might cause the process
to stop responding.</li>
<li><code>0</code> can be sent to test for the existence of a process, it has no effect if
the process exists, but will throw an error if the process does not exist.</li>
</ul>
<p>Windows does not support signals so has no equivalent to termination by signal,
but Node.js offers some emulation with <a href="#processkillpid-signal"><code>process.kill()</code></a>, and
<a href="child_process.html#subprocesskillsignal"><code>subprocess.kill()</code></a>:</p>
<ul>
<li>Sending <code>SIGINT</code>, <code>SIGTERM</code>, and <code>SIGKILL</code> will cause the unconditional
termination of the target process, and afterwards, subprocess will report that
the process was terminated by signal.</li>
<li>Sending signal <code>0</code> can be used as a platform independent way to test for the
existence of a process.</li>
</ul>
</section><section><h3><code>process.abort()</code><span><a class="mark" href="#processabort" id="processabort">#</a></span><a aria-hidden="true" class="legacy" id="process_process_abort"></a></h3>
<div class="api_metadata">
<span>Added in: v0.7.0</span>
</div>
<p>The <code>process.abort()</code> method causes the Node.js process to exit immediately and
generate a core file.</p>
<p>This feature is not available in <a href="worker_threads.html#class-worker"><code>Worker</code></a> threads.</p>
</section><section><h3><code>process.allowedNodeEnvironmentFlags</code><span><a class="mark" href="#processallowednodeenvironmentflags" id="processallowednodeenvironmentflags">#</a></span><a aria-hidden="true" class="legacy" id="process_process_allowednodeenvironmentflags"></a></h3>
<div class="api_metadata">
<span>Added in: v10.10.0</span>
</div>
<ul>
<li><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set" class="type"><Set></a></li>
</ul>
<p>The <code>process.allowedNodeEnvironmentFlags</code> property is a special,
read-only <code>Set</code> of flags allowable within the <a href="cli.html#node_optionsoptions"><code>NODE_OPTIONS</code></a>
environment variable.</p>
<p><code>process.allowedNodeEnvironmentFlags</code> extends <code>Set</code>, but overrides
<code>Set.prototype.has</code> to recognize several different possible flag
representations. <code>process.allowedNodeEnvironmentFlags.has()</code> will
return <code>true</code> in the following cases:</p>
<ul>
<li>Flags may omit leading single (<code>-</code>) or double (<code>--</code>) dashes; e.g.,
<code>inspect-brk</code> for <code>--inspect-brk</code>, or <code>r</code> for <code>-r</code>.</li>
<li>Flags passed through to V8 (as listed in <code>--v8-options</code>) may replace
one or more <em>non-leading</em> dashes for an underscore, or vice-versa;
e.g., <code>--perf_basic_prof</code>, <code>--perf-basic-prof</code>, <code>--perf_basic-prof</code>,
etc.</li>
<li>Flags may contain one or more equals (<code>=</code>) characters; all
characters after and including the first equals will be ignored;
e.g., <code>--stack-trace-limit=100</code>.</li>
<li>Flags <em>must</em> be allowable within <a href="cli.html#node_optionsoptions"><code>NODE_OPTIONS</code></a>.</li>
</ul>
<p>When iterating over <code>process.allowedNodeEnvironmentFlags</code>, flags will
appear only <em>once</em>; each will begin with one or more dashes. Flags
passed through to V8 will contain underscores instead of non-leading
dashes:</p>
<pre class="with-64-chars"><input class="js-flavor-toggle" type="checkbox" checked aria-label="Show modern ES modules syntax"><code class="language-js mjs"><span class="hljs-keyword">import</span> { allowedNodeEnvironmentFlags } <span class="hljs-keyword">from</span> <span class="hljs-string">'node:process'</span>;
allowedNodeEnvironmentFlags.<span class="hljs-title function_">forEach</span>(<span class="hljs-function">(<span class="hljs-params">flag</span>) =></span> {
<span class="hljs-comment">// -r</span>
<span class="hljs-comment">// --inspect-brk</span>
<span class="hljs-comment">// --abort_on_uncaught_exception</span>
<span class="hljs-comment">// ...</span>
});</code><code class="language-js cjs"><span class="hljs-keyword">const</span> { allowedNodeEnvironmentFlags } = <span class="hljs-built_in">require</span>(<span class="hljs-string">'node:process'</span>);
allowedNodeEnvironmentFlags.<span class="hljs-title function_">forEach</span>(<span class="hljs-function">(<span class="hljs-params">flag</span>) =></span> {
<span class="hljs-comment">// -r</span>
<span class="hljs-comment">// --inspect-brk</span>
<span class="hljs-comment">// --abort_on_uncaught_exception</span>
<span class="hljs-comment">// ...</span>
});</code><button class="copy-button">copy</button></pre>
<p>The methods <code>add()</code>, <code>clear()</code>, and <code>delete()</code> of
<code>process.allowedNodeEnvironmentFlags</code> do nothing, and will fail
silently.</p>
<p>If Node.js was compiled <em>without</em> <a href="cli.html#node_optionsoptions"><code>NODE_OPTIONS</code></a> support (shown in
<a href="#processconfig"><code>process.config</code></a>), <code>process.allowedNodeEnvironmentFlags</code> will
contain what <em>would have</em> been allowable.</p>
</section><section><h3><code>process.arch</code><span><a class="mark" href="#processarch" id="processarch">#</a></span><a aria-hidden="true" class="legacy" id="process_process_arch"></a></h3>
<div class="api_metadata">
<span>Added in: v0.5.0</span>
</div>
<ul>
<li><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type"><string></a></li>
</ul>
<p>The operating system CPU architecture for which the Node.js binary was compiled.
Possible values are: <code>'arm'</code>, <code>'arm64'</code>, <code>'ia32'</code>, <code>'loong64'</code>, <code>'mips'</code>,
<code>'mipsel'</code>, <code>'ppc'</code>, <code>'ppc64'</code>, <code>'riscv64'</code>, <code>'s390'</code>, <code>'s390x'</code>, and <code>'x64'</code>.</p>
<pre class="with-41-chars"><input class="js-flavor-toggle" type="checkbox" checked aria-label="Show modern ES modules syntax"><code class="language-js mjs"><span class="hljs-keyword">import</span> { arch } <span class="hljs-keyword">from</span> <span class="hljs-string">'node:process'</span>;
<span class="hljs-variable language_">console</span>.<span class="hljs-title function_">log</span>(<span class="hljs-string">`This processor architecture is <span class="hljs-subst">${arch}</span>`</span>);</code><code class="language-js cjs"><span class="hljs-keyword">const</span> { arch } = <span class="hljs-built_in">require</span>(<span class="hljs-string">'node:process'</span>);
<span class="hljs-variable language_">console</span>.<span class="hljs-title function_">log</span>(<span class="hljs-string">`This processor architecture is <span class="hljs-subst">${arch}</span>`</span>);</code><button class="copy-button">copy</button></pre>
</section><section><h3><code>process.argv</code><span><a class="mark" href="#processargv" id="processargv">#</a></span><a aria-hidden="true" class="legacy" id="process_process_argv"></a></h3>
<div class="api_metadata">
<span>Added in: v0.1.27</span>
</div>
<ul>
<li><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type"><string[]></a></li>
</ul>
<p>The <code>process.argv</code> property returns an array containing the command-line
arguments passed when the Node.js process was launched. The first element will
be <a href="#processexecpath"><code>process.execPath</code></a>. See <code>process.argv0</code> if access to the original value
of <code>argv[0]</code> is needed. The second element will be the path to the JavaScript
file being executed. The remaining elements will be any additional command-line
arguments.</p>
<p>For example, assuming the following script for <code>process-args.js</code>:</p>
<pre class="with-41-chars"><input class="js-flavor-toggle" type="checkbox" checked aria-label="Show modern ES modules syntax"><code class="language-js mjs"><span class="hljs-keyword">import</span> { argv } <span class="hljs-keyword">from</span> <span class="hljs-string">'node:process'</span>;
<span class="hljs-comment">// print process.argv</span>
argv.<span class="hljs-title function_">forEach</span>(<span class="hljs-function">(<span class="hljs-params">val, index</span>) =></span> {
<span class="hljs-variable language_">console</span>.<span class="hljs-title function_">log</span>(<span class="hljs-string">`<span class="hljs-subst">${index}</span>: <span class="hljs-subst">${val}</span>`</span>);
});</code><code class="language-js cjs"><span class="hljs-keyword">const</span> { argv } = <span class="hljs-built_in">require</span>(<span class="hljs-string">'node:process'</span>);
<span class="hljs-comment">// print process.argv</span>
argv.<span class="hljs-title function_">forEach</span>(<span class="hljs-function">(<span class="hljs-params">val, index</span>) =></span> {
<span class="hljs-variable language_">console</span>.<span class="hljs-title function_">log</span>(<span class="hljs-string">`<span class="hljs-subst">${index}</span>: <span class="hljs-subst">${val}</span>`</span>);
});</code><button class="copy-button">copy</button></pre>
<p>Launching the Node.js process as:</p>
<pre><code class="language-bash">node process-args.js one two=three four</code> <button class="copy-button">copy</button></pre>
<p>Would generate the output:</p>
<pre><code class="language-text">0: /usr/local/bin/node
1: /Users/mjr/work/node/process-args.js
2: one
3: two=three
4: four</code> <button class="copy-button">copy</button></pre>
</section><section><h3><code>process.argv0</code><span><a class="mark" href="#processargv0" id="processargv0">#</a></span><a aria-hidden="true" class="legacy" id="process_process_argv0"></a></h3>
<div class="api_metadata">
<span>Added in: v6.4.0</span>
</div>
<ul>
<li><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type"><string></a></li>
</ul>
<p>The <code>process.argv0</code> property stores a read-only copy of the original value of
<code>argv[0]</code> passed when Node.js starts.</p>
<pre><code class="language-console"><span class="hljs-meta prompt_">$ </span><span class="language-bash">bash -c <span class="hljs-string">'exec -a customArgv0 ./node'</span></span>
<span class="hljs-meta prompt_">> </span><span class="language-bash">process.argv[0]</span>
'/Volumes/code/external/node/out/Release/node'
<span class="hljs-meta prompt_">> </span><span class="language-bash">process.argv0</span>
'customArgv0'</code> <button class="copy-button">copy</button></pre>
</section><section><h3><code>process.channel</code><span><a class="mark" href="#processchannel" id="processchannel">#</a></span><a aria-hidden="true" class="legacy" id="process_process_channel"></a></h3>
<div class="api_metadata">
<details class="changelog"><summary>History</summary>
<table>
<tbody><tr><th>Version</th><th>Changes</th></tr>
<tr><td>v14.0.0</td>
<td><p>The object no longer accidentally exposes native C++ bindings.</p></td></tr>
<tr><td>v7.1.0</td>
<td><p><span>Added in: v7.1.0</span></p></td></tr>
</tbody></table>
</details>
</div>
<ul>
<li><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object" class="type"><Object></a></li>
</ul>
<p>If the Node.js process was spawned with an IPC channel (see the
<a href="child_process.html">Child Process</a> documentation), the <code>process.channel</code>
property is a reference to the IPC channel. If no IPC channel exists, this
property is <code>undefined</code>.</p>
<h4><code>process.channel.ref()</code><span><a class="mark" href="#processchannelref" id="processchannelref">#</a></span><a aria-hidden="true" class="legacy" id="process_process_channel_ref"></a></h4>
<div class="api_metadata">
<span>Added in: v7.1.0</span>
</div>
<p>This method makes the IPC channel keep the event loop of the process
running if <code>.unref()</code> has been called before.</p>
<p>Typically, this is managed through the number of <code>'disconnect'</code> and <code>'message'</code>
listeners on the <code>process</code> object. However, this method can be used to
explicitly request a specific behavior.</p>
<h4><code>process.channel.unref()</code><span><a class="mark" href="#processchannelunref" id="processchannelunref">#</a></span><a aria-hidden="true" class="legacy" id="process_process_channel_unref"></a></h4>
<div class="api_metadata">
<span>Added in: v7.1.0</span>
</div>
<p>This method makes the IPC channel not keep the event loop of the process
running, and lets it finish even while the channel is open.</p>
<p>Typically, this is managed through the number of <code>'disconnect'</code> and <code>'message'</code>
listeners on the <code>process</code> object. However, this method can be used to
explicitly request a specific behavior.</p>
</section><section><h3><code>process.chdir(directory)</code><span><a class="mark" href="#processchdirdirectory" id="processchdirdirectory">#</a></span><a aria-hidden="true" class="legacy" id="process_process_chdir_directory"></a></h3>
<div class="api_metadata">
<span>Added in: v0.1.17</span>
</div>
<ul>
<li><code>directory</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type"><string></a></li>
</ul>
<p>The <code>process.chdir()</code> method changes the current working directory of the
Node.js process or throws an exception if doing so fails (for instance, if
the specified <code>directory</code> does not exist).</p>
<pre class="with-47-chars"><input class="js-flavor-toggle" type="checkbox" checked aria-label="Show modern ES modules syntax"><code class="language-js mjs"><span class="hljs-keyword">import</span> { chdir, cwd } <span class="hljs-keyword">from</span> <span class="hljs-string">'node:process'</span>;
<span class="hljs-variable language_">console</span>.<span class="hljs-title function_">log</span>(<span class="hljs-string">`Starting directory: <span class="hljs-subst">${cwd()}</span>`</span>);
<span class="hljs-keyword">try</span> {
<span class="hljs-title function_">chdir</span>(<span class="hljs-string">'/tmp'</span>);
<span class="hljs-variable language_">console</span>.<span class="hljs-title function_">log</span>(<span class="hljs-string">`New directory: <span class="hljs-subst">${cwd()}</span>`</span>);
} <span class="hljs-keyword">catch</span> (err) {
<span class="hljs-variable language_">console</span>.<span class="hljs-title function_">error</span>(<span class="hljs-string">`chdir: <span class="hljs-subst">${err}</span>`</span>);
}</code><code class="language-js cjs"><span class="hljs-keyword">const</span> { chdir, cwd } = <span class="hljs-built_in">require</span>(<span class="hljs-string">'node:process'</span>);
<span class="hljs-variable language_">console</span>.<span class="hljs-title function_">log</span>(<span class="hljs-string">`Starting directory: <span class="hljs-subst">${cwd()}</span>`</span>);
<span class="hljs-keyword">try</span> {
<span class="hljs-title function_">chdir</span>(<span class="hljs-string">'/tmp'</span>);
<span class="hljs-variable language_">console</span>.<span class="hljs-title function_">log</span>(<span class="hljs-string">`New directory: <span class="hljs-subst">${cwd()}</span>`</span>);
} <span class="hljs-keyword">catch</span> (err) {
<span class="hljs-variable language_">console</span>.<span class="hljs-title function_">error</span>(<span class="hljs-string">`chdir: <span class="hljs-subst">${err}</span>`</span>);
}</code><button class="copy-button">copy</button></pre>
<p>This feature is not available in <a href="worker_threads.html#class-worker"><code>Worker</code></a> threads.</p>
</section><section><h3><code>process.config</code><span><a class="mark" href="#processconfig" id="processconfig">#</a></span><a aria-hidden="true" class="legacy" id="process_process_config"></a></h3>
<div class="api_metadata">
<details class="changelog"><summary>History</summary>
<table>
<tbody><tr><th>Version</th><th>Changes</th></tr>
<tr><td>v19.0.0</td>
<td><p>The <code>process.config</code> object is now frozen.</p></td></tr>
<tr><td>v16.0.0</td>
<td><p>Modifying process.config has been deprecated.</p></td></tr>
<tr><td>v0.7.7</td>
<td><p><span>Added in: v0.7.7</span></p></td></tr>
</tbody></table>
</details>
</div>
<ul>
<li><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object" class="type"><Object></a></li>
</ul>
<p>The <code>process.config</code> property returns a frozen <code>Object</code> containing the
JavaScript representation of the configure options used to compile the current
Node.js executable. This is the same as the <code>config.gypi</code> file that was produced
when running the <code>./configure</code> script.</p>
<p>An example of the possible output looks like:</p>
<!-- eslint-skip -->
<pre><code class="language-js">{
<span class="hljs-attr">target_defaults</span>:
{ <span class="hljs-attr">cflags</span>: [],
<span class="hljs-attr">default_configuration</span>: <span class="hljs-string">'Release'</span>,
<span class="hljs-attr">defines</span>: [],
<span class="hljs-attr">include_dirs</span>: [],
<span class="hljs-attr">libraries</span>: [] },
<span class="hljs-attr">variables</span>:
{
<span class="hljs-attr">host_arch</span>: <span class="hljs-string">'x64'</span>,
<span class="hljs-attr">napi_build_version</span>: <span class="hljs-number">5</span>,
<span class="hljs-attr">node_install_npm</span>: <span class="hljs-string">'true'</span>,
<span class="hljs-attr">node_prefix</span>: <span class="hljs-string">''</span>,
<span class="hljs-attr">node_shared_cares</span>: <span class="hljs-string">'false'</span>,
<span class="hljs-attr">node_shared_http_parser</span>: <span class="hljs-string">'false'</span>,
<span class="hljs-attr">node_shared_libuv</span>: <span class="hljs-string">'false'</span>,
<span class="hljs-attr">node_shared_zlib</span>: <span class="hljs-string">'false'</span>,
<span class="hljs-attr">node_use_openssl</span>: <span class="hljs-string">'true'</span>,
<span class="hljs-attr">node_shared_openssl</span>: <span class="hljs-string">'false'</span>,
<span class="hljs-attr">target_arch</span>: <span class="hljs-string">'x64'</span>,
<span class="hljs-attr">v8_use_snapshot</span>: <span class="hljs-number">1</span>
}
}</code> <button class="copy-button">copy</button></pre>
</section><section><h3><code>process.connected</code><span><a class="mark" href="#processconnected" id="processconnected">#</a></span><a aria-hidden="true" class="legacy" id="process_process_connected"></a></h3>
<div class="api_metadata">
<span>Added in: v0.7.2</span>
</div>
<ul>
<li><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Boolean_type" class="type"><boolean></a></li>
</ul>
<p>If the Node.js process is spawned with an IPC channel (see the <a href="child_process.html">Child Process</a>
and <a href="cluster.html">Cluster</a> documentation), the <code>process.connected</code> property will return
<code>true</code> so long as the IPC channel is connected and will return <code>false</code> after
<code>process.disconnect()</code> is called.</p>
<p>Once <code>process.connected</code> is <code>false</code>, it is no longer possible to send messages
over the IPC channel using <code>process.send()</code>.</p>
</section><section><h3><code>process.constrainedMemory()</code><span><a class="mark" href="#processconstrainedmemory" id="processconstrainedmemory">#</a></span><a aria-hidden="true" class="legacy" id="process_process_constrainedmemory"></a></h3>
<div class="api_metadata">
<details class="changelog"><summary>History</summary>
<table>
<tbody><tr><th>Version</th><th>Changes</th></tr>
<tr><td>v22.0.0</td>
<td><p>Aligned return value with <code>uv_get_constrained_memory</code>.</p></td></tr>
<tr><td>v19.6.0, v18.15.0</td>
<td><p><span>Added in: v19.6.0, v18.15.0</span></p></td></tr>
</tbody></table>
</details>
</div>
<p></p><div class="api_stability api_stability_1"><a href="documentation.html#stability-index">Stability: 1</a> - Experimental</div><p></p>
<ul>
<li><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type" class="type"><number></a></li>
</ul>
<p>Gets the amount of memory available to the process (in bytes) based on
limits imposed by the OS. If there is no such constraint, or the constraint
is unknown, <code>0</code> is returned.</p>
<p>See <a href="https://docs.libuv.org/en/v1.x/misc.html#c.uv_get_constrained_memory"><code>uv_get_constrained_memory</code></a> for more
information.</p>
</section><section><h3><code>process.availableMemory()</code><span><a class="mark" href="#processavailablememory" id="processavailablememory">#</a></span><a aria-hidden="true" class="legacy" id="process_process_availablememory"></a></h3>
<div class="api_metadata">
<span>Added in: v22.0.0</span>
</div>
<p></p><div class="api_stability api_stability_1"><a href="documentation.html#stability-index">Stability: 1</a> - Experimental</div><p></p>
<ul>
<li><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type" class="type"><number></a></li>
</ul>
<p>Gets the amount of free memory that is still available to the process
(in bytes).</p>
<p>See <a href="https://docs.libuv.org/en/v1.x/misc.html#c.uv_get_available_memory"><code>uv_get_available_memory</code></a> for more
information.</p>
</section><section><h3><code>process.cpuUsage([previousValue])</code><span><a class="mark" href="#processcpuusagepreviousvalue" id="processcpuusagepreviousvalue">#</a></span><a aria-hidden="true" class="legacy" id="process_process_cpuusage_previousvalue"></a></h3>
<div class="api_metadata">
<span>Added in: v6.1.0</span>
</div>
<ul>
<li><code>previousValue</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object" class="type"><Object></a> A previous return value from calling
<code>process.cpuUsage()</code></li>
<li>Returns: <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object" class="type"><Object></a>
<ul>
<li><code>user</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type" class="type"><integer></a></li>
<li><code>system</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type" class="type"><integer></a></li>
</ul>
</li>
</ul>
<p>The <code>process.cpuUsage()</code> method returns the user and system CPU time usage of
the current process, in an object with properties <code>user</code> and <code>system</code>, whose
values are microsecond values (millionth of a second). These values measure time
spent in user and system code respectively, and may end up being greater than
actual elapsed time if multiple CPU cores are performing work for this process.</p>
<p>The result of a previous call to <code>process.cpuUsage()</code> can be passed as the
argument to the function, to get a diff reading.</p>
<pre class="with-45-chars"><input class="js-flavor-toggle" type="checkbox" checked aria-label="Show modern ES modules syntax"><code class="language-js mjs"><span class="hljs-keyword">import</span> { cpuUsage } <span class="hljs-keyword">from</span> <span class="hljs-string">'node:process'</span>;
<span class="hljs-keyword">const</span> startUsage = <span class="hljs-title function_">cpuUsage</span>();
<span class="hljs-comment">// { user: 38579, system: 6986 }</span>
<span class="hljs-comment">// spin the CPU for 500 milliseconds</span>
<span class="hljs-keyword">const</span> now = <span class="hljs-title class_">Date</span>.<span class="hljs-title function_">now</span>();
<span class="hljs-keyword">while</span> (<span class="hljs-title class_">Date</span>.<span class="hljs-title function_">now</span>() - now < <span class="hljs-number">500</span>);
<span class="hljs-variable language_">console</span>.<span class="hljs-title function_">log</span>(<span class="hljs-title function_">cpuUsage</span>(startUsage));
<span class="hljs-comment">// { user: 514883, system: 11226 }</span></code><code class="language-js cjs"><span class="hljs-keyword">const</span> { cpuUsage } = <span class="hljs-built_in">require</span>(<span class="hljs-string">'node:process'</span>);
<span class="hljs-keyword">const</span> startUsage = <span class="hljs-title function_">cpuUsage</span>();
<span class="hljs-comment">// { user: 38579, system: 6986 }</span>
<span class="hljs-comment">// spin the CPU for 500 milliseconds</span>
<span class="hljs-keyword">const</span> now = <span class="hljs-title class_">Date</span>.<span class="hljs-title function_">now</span>();
<span class="hljs-keyword">while</span> (<span class="hljs-title class_">Date</span>.<span class="hljs-title function_">now</span>() - now < <span class="hljs-number">500</span>);
<span class="hljs-variable language_">console</span>.<span class="hljs-title function_">log</span>(<span class="hljs-title function_">cpuUsage</span>(startUsage));
<span class="hljs-comment">// { user: 514883, system: 11226 }</span></code><button class="copy-button">copy</button></pre>
</section><section><h3><code>process.cwd()</code><span><a class="mark" href="#processcwd" id="processcwd">#</a></span><a aria-hidden="true" class="legacy" id="process_process_cwd"></a></h3>
<div class="api_metadata">
<span>Added in: v0.1.8</span>
</div>
<ul>
<li>Returns: <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type"><string></a></li>
</ul>
<p>The <code>process.cwd()</code> method returns the current working directory of the Node.js
process.</p>
<pre class="with-40-chars"><input class="js-flavor-toggle" type="checkbox" checked aria-label="Show modern ES modules syntax"><code class="language-js mjs"><span class="hljs-keyword">import</span> { cwd } <span class="hljs-keyword">from</span> <span class="hljs-string">'node:process'</span>;
<span class="hljs-variable language_">console</span>.<span class="hljs-title function_">log</span>(<span class="hljs-string">`Current directory: <span class="hljs-subst">${cwd()}</span>`</span>);</code><code class="language-js cjs"><span class="hljs-keyword">const</span> { cwd } = <span class="hljs-built_in">require</span>(<span class="hljs-string">'node:process'</span>);
<span class="hljs-variable language_">console</span>.<span class="hljs-title function_">log</span>(<span class="hljs-string">`Current directory: <span class="hljs-subst">${cwd()}</span>`</span>);</code><button class="copy-button">copy</button></pre>
</section><section><h3><code>process.debugPort</code><span><a class="mark" href="#processdebugport" id="processdebugport">#</a></span><a aria-hidden="true" class="legacy" id="process_process_debugport"></a></h3>
<div class="api_metadata">
<span>Added in: v0.7.2</span>
</div>
<ul>
<li><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type" class="type"><number></a></li>
</ul>
<p>The port used by the Node.js debugger when enabled.</p>
<pre class="with-40-chars"><input class="js-flavor-toggle" type="checkbox" checked aria-label="Show modern ES modules syntax"><code class="language-js mjs"><span class="hljs-keyword">import</span> process <span class="hljs-keyword">from</span> <span class="hljs-string">'node:process'</span>;
process.<span class="hljs-property">debugPort</span> = <span class="hljs-number">5858</span>;</code><code class="language-js cjs"><span class="hljs-keyword">const</span> process = <span class="hljs-built_in">require</span>(<span class="hljs-string">'node:process'</span>);
process.<span class="hljs-property">debugPort</span> = <span class="hljs-number">5858</span>;</code><button class="copy-button">copy</button></pre>
</section><section><h3><code>process.disconnect()</code><span><a class="mark" href="#processdisconnect" id="processdisconnect">#</a></span><a aria-hidden="true" class="legacy" id="process_process_disconnect"></a></h3>
<div class="api_metadata">
<span>Added in: v0.7.2</span>
</div>
<p>If the Node.js process is spawned with an IPC channel (see the <a href="child_process.html">Child Process</a>
and <a href="cluster.html">Cluster</a> documentation), the <code>process.disconnect()</code> method will close the
IPC channel to the parent process, allowing the child process to exit gracefully
once there are no other connections keeping it alive.</p>
<p>The effect of calling <code>process.disconnect()</code> is the same as calling
<a href="child_process.html#subprocessdisconnect"><code>ChildProcess.disconnect()</code></a> from the parent process.</p>
<p>If the Node.js process was not spawned with an IPC channel,
<code>process.disconnect()</code> will be <code>undefined</code>.</p>
</section><section><h3><code>process.dlopen(module, filename[, flags])</code><span><a class="mark" href="#processdlopenmodule-filename-flags" id="processdlopenmodule-filename-flags">#</a></span><a aria-hidden="true" class="legacy" id="process_process_dlopen_module_filename_flags"></a></h3>
<div class="api_metadata">
<details class="changelog"><summary>History</summary>
<table>
<tbody><tr><th>Version</th><th>Changes</th></tr>
<tr><td>v9.0.0</td>
<td><p>Added support for the <code>flags</code> argument.</p></td></tr>
<tr><td>v0.1.16</td>
<td><p><span>Added in: v0.1.16</span></p></td></tr>
</tbody></table>
</details>
</div>
<ul>
<li><code>module</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object" class="type"><Object></a></li>
<li><code>filename</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type"><string></a></li>
<li><code>flags</code> <a href="os.html#dlopen-constants" class="type"><os.constants.dlopen></a> <strong>Default:</strong> <code>os.constants.dlopen.RTLD_LAZY</code></li>
</ul>
<p>The <code>process.dlopen()</code> method allows dynamically loading shared objects. It is
primarily used by <code>require()</code> to load C++ Addons, and should not be used
directly, except in special cases. In other words, <a href="globals.html#require"><code>require()</code></a> should be
preferred over <code>process.dlopen()</code> unless there are specific reasons such as
custom dlopen flags or loading from ES modules.</p>
<p>The <code>flags</code> argument is an integer that allows to specify dlopen
behavior. See the <a href="os.html#dlopen-constants"><code>os.constants.dlopen</code></a> documentation for details.</p>
<p>An important requirement when calling <code>process.dlopen()</code> is that the <code>module</code>
instance must be passed. Functions exported by the C++ Addon are then
accessible via <code>module.exports</code>.</p>
<p>The example below shows how to load a C++ Addon, named <code>local.node</code>,
that exports a <code>foo</code> function. All the symbols are loaded before
the call returns, by passing the <code>RTLD_NOW</code> constant. In this example
the constant is assumed to be available.</p>
<pre class="with-43-chars"><input class="js-flavor-toggle" type="checkbox" checked aria-label="Show modern ES modules syntax"><code class="language-js mjs"><span class="hljs-keyword">import</span> { dlopen } <span class="hljs-keyword">from</span> <span class="hljs-string">'node:process'</span>;
<span class="hljs-keyword">import</span> { constants } <span class="hljs-keyword">from</span> <span class="hljs-string">'node:os'</span>;
<span class="hljs-keyword">import</span> { fileURLToPath } <span class="hljs-keyword">from</span> <span class="hljs-string">'node:url'</span>;
<span class="hljs-keyword">const</span> <span class="hljs-variable language_">module</span> = { <span class="hljs-attr">exports</span>: {} };
<span class="hljs-title function_">dlopen</span>(<span class="hljs-variable language_">module</span>, <span class="hljs-title function_">fileURLToPath</span>(<span class="hljs-keyword">new</span> <span class="hljs-title function_">URL</span>(<span class="hljs-string">'local.node'</span>, <span class="hljs-keyword">import</span>.<span class="hljs-property">meta</span>.<span class="hljs-property">url</span>)),
constants.<span class="hljs-property">dlopen</span>.<span class="hljs-property">RTLD_NOW</span>);
<span class="hljs-variable language_">module</span>.<span class="hljs-property">exports</span>.<span class="hljs-title function_">foo</span>();</code><code class="language-js cjs"><span class="hljs-keyword">const</span> { dlopen } = <span class="hljs-built_in">require</span>(<span class="hljs-string">'node:process'</span>);
<span class="hljs-keyword">const</span> { constants } = <span class="hljs-built_in">require</span>(<span class="hljs-string">'node:os'</span>);
<span class="hljs-keyword">const</span> { join } = <span class="hljs-built_in">require</span>(<span class="hljs-string">'node:path'</span>);
<span class="hljs-keyword">const</span> <span class="hljs-variable language_">module</span> = { <span class="hljs-attr">exports</span>: {} };
<span class="hljs-title function_">dlopen</span>(<span class="hljs-variable language_">module</span>, <span class="hljs-title function_">join</span>(__dirname, <span class="hljs-string">'local.node'</span>), constants.<span class="hljs-property">dlopen</span>.<span class="hljs-property">RTLD_NOW</span>);
<span class="hljs-variable language_">module</span>.<span class="hljs-property">exports</span>.<span class="hljs-title function_">foo</span>();</code><button class="copy-button">copy</button></pre>
</section><section><h3><code>process.emitWarning(warning[, options])</code><span><a class="mark" href="#processemitwarningwarning-options" id="processemitwarningwarning-options">#</a></span><a aria-hidden="true" class="legacy" id="process_process_emitwarning_warning_options"></a></h3>
<div class="api_metadata">
<span>Added in: v8.0.0</span>
</div>
<ul>
<li><code>warning</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type"><string></a> | <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Error" class="type"><Error></a> The warning to emit.</li>
<li><code>options</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object" class="type"><Object></a>
<ul>
<li><code>type</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type"><string></a> When <code>warning</code> is a <code>String</code>, <code>type</code> is the name to use
for the <em>type</em> of warning being emitted. <strong>Default:</strong> <code>'Warning'</code>.</li>
<li><code>code</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type"><string></a> A unique identifier for the warning instance being emitted.</li>
<li><code>ctor</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function" class="type"><Function></a> When <code>warning</code> is a <code>String</code>, <code>ctor</code> is an optional
function used to limit the generated stack trace. <strong>Default:</strong>
<code>process.emitWarning</code>.</li>
<li><code>detail</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type"><string></a> Additional text to include with the error.</li>
</ul>
</li>
</ul>
<p>The <code>process.emitWarning()</code> method can be used to emit custom or application
specific process warnings. These can be listened for by adding a handler to the
<a href="#event-warning"><code>'warning'</code></a> event.</p>
<pre class="with-48-chars"><input class="js-flavor-toggle" type="checkbox" checked aria-label="Show modern ES modules syntax"><code class="language-js mjs"><span class="hljs-keyword">import</span> { emitWarning } <span class="hljs-keyword">from</span> <span class="hljs-string">'node:process'</span>;
<span class="hljs-comment">// Emit a warning with a code and additional detail.</span>
<span class="hljs-title function_">emitWarning</span>(<span class="hljs-string">'Something happened!'</span>, {
<span class="hljs-attr">code</span>: <span class="hljs-string">'MY_WARNING'</span>,
<span class="hljs-attr">detail</span>: <span class="hljs-string">'This is some additional information'</span>,
});
<span class="hljs-comment">// Emits:</span>
<span class="hljs-comment">// (node:56338) [MY_WARNING] Warning: Something happened!</span>
<span class="hljs-comment">// This is some additional information</span></code><code class="language-js cjs"><span class="hljs-keyword">const</span> { emitWarning } = <span class="hljs-built_in">require</span>(<span class="hljs-string">'node:process'</span>);
<span class="hljs-comment">// Emit a warning with a code and additional detail.</span>
<span class="hljs-title function_">emitWarning</span>(<span class="hljs-string">'Something happened!'</span>, {
<span class="hljs-attr">code</span>: <span class="hljs-string">'MY_WARNING'</span>,
<span class="hljs-attr">detail</span>: <span class="hljs-string">'This is some additional information'</span>,
});
<span class="hljs-comment">// Emits:</span>
<span class="hljs-comment">// (node:56338) [MY_WARNING] Warning: Something happened!</span>
<span class="hljs-comment">// This is some additional information</span></code><button class="copy-button">copy</button></pre>
<p>In this example, an <code>Error</code> object is generated internally by
<code>process.emitWarning()</code> and passed through to the
<a href="#event-warning"><code>'warning'</code></a> handler.</p>
<pre class="with-40-chars"><input class="js-flavor-toggle" type="checkbox" checked aria-label="Show modern ES modules syntax"><code class="language-js mjs"><span class="hljs-keyword">import</span> process <span class="hljs-keyword">from</span> <span class="hljs-string">'node:process'</span>;
process.<span class="hljs-title function_">on</span>(<span class="hljs-string">'warning'</span>, <span class="hljs-function">(<span class="hljs-params">warning</span>) =></span> {
<span class="hljs-variable language_">console</span>.<span class="hljs-title function_">warn</span>(warning.<span class="hljs-property">name</span>); <span class="hljs-comment">// 'Warning'</span>
<span class="hljs-variable language_">console</span>.<span class="hljs-title function_">warn</span>(warning.<span class="hljs-property">message</span>); <span class="hljs-comment">// 'Something happened!'</span>
<span class="hljs-variable language_">console</span>.<span class="hljs-title function_">warn</span>(warning.<span class="hljs-property">code</span>); <span class="hljs-comment">// 'MY_WARNING'</span>
<span class="hljs-variable language_">console</span>.<span class="hljs-title function_">warn</span>(warning.<span class="hljs-property">stack</span>); <span class="hljs-comment">// Stack trace</span>
<span class="hljs-variable language_">console</span>.<span class="hljs-title function_">warn</span>(warning.<span class="hljs-property">detail</span>); <span class="hljs-comment">// 'This is some additional information'</span>
});</code><code class="language-js cjs"><span class="hljs-keyword">const</span> process = <span class="hljs-built_in">require</span>(<span class="hljs-string">'node:process'</span>);
process.<span class="hljs-title function_">on</span>(<span class="hljs-string">'warning'</span>, <span class="hljs-function">(<span class="hljs-params">warning</span>) =></span> {
<span class="hljs-variable language_">console</span>.<span class="hljs-title function_">warn</span>(warning.<span class="hljs-property">name</span>); <span class="hljs-comment">// 'Warning'</span>
<span class="hljs-variable language_">console</span>.<span class="hljs-title function_">warn</span>(warning.<span class="hljs-property">message</span>); <span class="hljs-comment">// 'Something happened!'</span>
<span class="hljs-variable language_">console</span>.<span class="hljs-title function_">warn</span>(warning.<span class="hljs-property">code</span>); <span class="hljs-comment">// 'MY_WARNING'</span>
<span class="hljs-variable language_">console</span>.<span class="hljs-title function_">warn</span>(warning.<span class="hljs-property">stack</span>); <span class="hljs-comment">// Stack trace</span>
<span class="hljs-variable language_">console</span>.<span class="hljs-title function_">warn</span>(warning.<span class="hljs-property">detail</span>); <span class="hljs-comment">// 'This is some additional information'</span>
});</code><button class="copy-button">copy</button></pre>
<p>If <code>warning</code> is passed as an <code>Error</code> object, the <code>options</code> argument is ignored.</p>
</section><section><h3><code>process.emitWarning(warning[, type[, code]][, ctor])</code><span><a class="mark" href="#processemitwarningwarning-type-code-ctor" id="processemitwarningwarning-type-code-ctor">#</a></span><a aria-hidden="true" class="legacy" id="process_process_emitwarning_warning_type_code_ctor"></a></h3>
<div class="api_metadata">
<span>Added in: v6.0.0</span>
</div>
<ul>
<li><code>warning</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type"><string></a> | <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Error" class="type"><Error></a> The warning to emit.</li>
<li><code>type</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type"><string></a> When <code>warning</code> is a <code>String</code>, <code>type</code> is the name to use
for the <em>type</em> of warning being emitted. <strong>Default:</strong> <code>'Warning'</code>.</li>
<li><code>code</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type"><string></a> A unique identifier for the warning instance being emitted.</li>
<li><code>ctor</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function" class="type"><Function></a> When <code>warning</code> is a <code>String</code>, <code>ctor</code> is an optional
function used to limit the generated stack trace. <strong>Default:</strong>
<code>process.emitWarning</code>.</li>
</ul>
<p>The <code>process.emitWarning()</code> method can be used to emit custom or application
specific process warnings. These can be listened for by adding a handler to the
<a href="#event-warning"><code>'warning'</code></a> event.</p>
<pre class="with-48-chars"><input class="js-flavor-toggle" type="checkbox" checked aria-label="Show modern ES modules syntax"><code class="language-js mjs"><span class="hljs-keyword">import</span> { emitWarning } <span class="hljs-keyword">from</span> <span class="hljs-string">'node:process'</span>;
<span class="hljs-comment">// Emit a warning using a string.</span>
<span class="hljs-title function_">emitWarning</span>(<span class="hljs-string">'Something happened!'</span>);
<span class="hljs-comment">// Emits: (node: 56338) Warning: Something happened!</span></code><code class="language-js cjs"><span class="hljs-keyword">const</span> { emitWarning } = <span class="hljs-built_in">require</span>(<span class="hljs-string">'node:process'</span>);
<span class="hljs-comment">// Emit a warning using a string.</span>
<span class="hljs-title function_">emitWarning</span>(<span class="hljs-string">'Something happened!'</span>);
<span class="hljs-comment">// Emits: (node: 56338) Warning: Something happened!</span></code><button class="copy-button">copy</button></pre>
<pre class="with-48-chars"><input class="js-flavor-toggle" type="checkbox" checked aria-label="Show modern ES modules syntax"><code class="language-js mjs"><span class="hljs-keyword">import</span> { emitWarning } <span class="hljs-keyword">from</span> <span class="hljs-string">'node:process'</span>;
<span class="hljs-comment">// Emit a warning using a string and a type.</span>
<span class="hljs-title function_">emitWarning</span>(<span class="hljs-string">'Something Happened!'</span>, <span class="hljs-string">'CustomWarning'</span>);
<span class="hljs-comment">// Emits: (node:56338) CustomWarning: Something Happened!</span></code><code class="language-js cjs"><span class="hljs-keyword">const</span> { emitWarning } = <span class="hljs-built_in">require</span>(<span class="hljs-string">'node:process'</span>);
<span class="hljs-comment">// Emit a warning using a string and a type.</span>
<span class="hljs-title function_">emitWarning</span>(<span class="hljs-string">'Something Happened!'</span>, <span class="hljs-string">'CustomWarning'</span>);
<span class="hljs-comment">// Emits: (node:56338) CustomWarning: Something Happened!</span></code><button class="copy-button">copy</button></pre>
<pre class="with-48-chars"><input class="js-flavor-toggle" type="checkbox" checked aria-label="Show modern ES modules syntax"><code class="language-js mjs"><span class="hljs-keyword">import</span> { emitWarning } <span class="hljs-keyword">from</span> <span class="hljs-string">'node:process'</span>;
<span class="hljs-title function_">emitWarning</span>(<span class="hljs-string">'Something happened!'</span>, <span class="hljs-string">'CustomWarning'</span>, <span class="hljs-string">'WARN001'</span>);
<span class="hljs-comment">// Emits: (node:56338) [WARN001] CustomWarning: Something happened!</span></code><code class="language-js cjs"><span class="hljs-keyword">const</span> { emitWarning } = <span class="hljs-built_in">require</span>(<span class="hljs-string">'node:process'</span>);
process.<span class="hljs-title function_">emitWarning</span>(<span class="hljs-string">'Something happened!'</span>, <span class="hljs-string">'CustomWarning'</span>, <span class="hljs-string">'WARN001'</span>);
<span class="hljs-comment">// Emits: (node:56338) [WARN001] CustomWarning: Something happened!</span></code><button class="copy-button">copy</button></pre>
<p>In each of the previous examples, an <code>Error</code> object is generated internally by
<code>process.emitWarning()</code> and passed through to the <a href="#event-warning"><code>'warning'</code></a>
handler.</p>
<pre class="with-40-chars"><input class="js-flavor-toggle" type="checkbox" checked aria-label="Show modern ES modules syntax"><code class="language-js mjs"><span class="hljs-keyword">import</span> process <span class="hljs-keyword">from</span> <span class="hljs-string">'node:process'</span>;
process.<span class="hljs-title function_">on</span>(<span class="hljs-string">'warning'</span>, <span class="hljs-function">(<span class="hljs-params">warning</span>) =></span> {
<span class="hljs-variable language_">console</span>.<span class="hljs-title function_">warn</span>(warning.<span class="hljs-property">name</span>);
<span class="hljs-variable language_">console</span>.<span class="hljs-title function_">warn</span>(warning.<span class="hljs-property">message</span>);
<span class="hljs-variable language_">console</span>.<span class="hljs-title function_">warn</span>(warning.<span class="hljs-property">code</span>);
<span class="hljs-variable language_">console</span>.<span class="hljs-title function_">warn</span>(warning.<span class="hljs-property">stack</span>);
});</code><code class="language-js cjs"><span class="hljs-keyword">const</span> process = <span class="hljs-built_in">require</span>(<span class="hljs-string">'node:process'</span>);
process.<span class="hljs-title function_">on</span>(<span class="hljs-string">'warning'</span>, <span class="hljs-function">(<span class="hljs-params">warning</span>) =></span> {
<span class="hljs-variable language_">console</span>.<span class="hljs-title function_">warn</span>(warning.<span class="hljs-property">name</span>);
<span class="hljs-variable language_">console</span>.<span class="hljs-title function_">warn</span>(warning.<span class="hljs-property">message</span>);
<span class="hljs-variable language_">console</span>.<span class="hljs-title function_">warn</span>(warning.<span class="hljs-property">code</span>);
<span class="hljs-variable language_">console</span>.<span class="hljs-title function_">warn</span>(warning.<span class="hljs-property">stack</span>);
});</code><button class="copy-button">copy</button></pre>
<p>If <code>warning</code> is passed as an <code>Error</code> object, it will be passed through to the
<code>'warning'</code> event handler unmodified (and the optional <code>type</code>,
<code>code</code> and <code>ctor</code> arguments will be ignored):</p>
<pre class="with-48-chars"><input class="js-flavor-toggle" type="checkbox" checked aria-label="Show modern ES modules syntax"><code class="language-js mjs"><span class="hljs-keyword">import</span> { emitWarning } <span class="hljs-keyword">from</span> <span class="hljs-string">'node:process'</span>;
<span class="hljs-comment">// Emit a warning using an Error object.</span>
<span class="hljs-keyword">const</span> myWarning = <span class="hljs-keyword">new</span> <span class="hljs-title class_">Error</span>(<span class="hljs-string">'Something happened!'</span>);
<span class="hljs-comment">// Use the Error name property to specify the type name</span>
myWarning.<span class="hljs-property">name</span> = <span class="hljs-string">'CustomWarning'</span>;
myWarning.<span class="hljs-property">code</span> = <span class="hljs-string">'WARN001'</span>;
<span class="hljs-title function_">emitWarning</span>(myWarning);
<span class="hljs-comment">// Emits: (node:56338) [WARN001] CustomWarning: Something happened!</span></code><code class="language-js cjs"><span class="hljs-keyword">const</span> { emitWarning } = <span class="hljs-built_in">require</span>(<span class="hljs-string">'node:process'</span>);
<span class="hljs-comment">// Emit a warning using an Error object.</span>
<span class="hljs-keyword">const</span> myWarning = <span class="hljs-keyword">new</span> <span class="hljs-title class_">Error</span>(<span class="hljs-string">'Something happened!'</span>);
<span class="hljs-comment">// Use the Error name property to specify the type name</span>
myWarning.<span class="hljs-property">name</span> = <span class="hljs-string">'CustomWarning'</span>;
myWarning.<span class="hljs-property">code</span> = <span class="hljs-string">'WARN001'</span>;
<span class="hljs-title function_">emitWarning</span>(myWarning);
<span class="hljs-comment">// Emits: (node:56338) [WARN001] CustomWarning: Something happened!</span></code><button class="copy-button">copy</button></pre>
<p>A <code>TypeError</code> is thrown if <code>warning</code> is anything other than a string or <code>Error</code>
object.</p>
<p>While process warnings use <code>Error</code> objects, the process warning
mechanism is <strong>not</strong> a replacement for normal error handling mechanisms.</p>
<p>The following additional handling is implemented if the warning <code>type</code> is
<code>'DeprecationWarning'</code>:</p>
<ul>
<li>If the <code>--throw-deprecation</code> command-line flag is used, the deprecation
warning is thrown as an exception rather than being emitted as an event.</li>
<li>If the <code>--no-deprecation</code> command-line flag is used, the deprecation
warning is suppressed.</li>
<li>If the <code>--trace-deprecation</code> command-line flag is used, the deprecation
warning is printed to <code>stderr</code> along with the full stack trace.</li>
</ul>
<h4>Avoiding duplicate warnings<span><a class="mark" href="#avoiding-duplicate-warnings" id="avoiding-duplicate-warnings">#</a></span><a aria-hidden="true" class="legacy" id="process_avoiding_duplicate_warnings"></a></h4>
<p>As a best practice, warnings should be emitted only once per process. To do
so, place the <code>emitWarning()</code> behind a boolean.</p>
<pre class="with-48-chars"><input class="js-flavor-toggle" type="checkbox" checked aria-label="Show modern ES modules syntax"><code class="language-js mjs"><span class="hljs-keyword">import</span> { emitWarning } <span class="hljs-keyword">from</span> <span class="hljs-string">'node:process'</span>;
<span class="hljs-keyword">function</span> <span class="hljs-title function_">emitMyWarning</span>(<span class="hljs-params"></span>) {
<span class="hljs-keyword">if</span> (!emitMyWarning.<span class="hljs-property">warned</span>) {
emitMyWarning.<span class="hljs-property">warned</span> = <span class="hljs-literal">true</span>;
<span class="hljs-title function_">emitWarning</span>(<span class="hljs-string">'Only warn once!'</span>);
}
}
<span class="hljs-title function_">emitMyWarning</span>();
<span class="hljs-comment">// Emits: (node: 56339) Warning: Only warn once!</span>
<span class="hljs-title function_">emitMyWarning</span>();
<span class="hljs-comment">// Emits nothing</span></code><code class="language-js cjs"><span class="hljs-keyword">const</span> { emitWarning } = <span class="hljs-built_in">require</span>(<span class="hljs-string">'node:process'</span>);
<span class="hljs-keyword">function</span> <span class="hljs-title function_">emitMyWarning</span>(<span class="hljs-params"></span>) {
<span class="hljs-keyword">if</span> (!emitMyWarning.<span class="hljs-property">warned</span>) {
emitMyWarning.<span class="hljs-property">warned</span> = <span class="hljs-literal">true</span>;
<span class="hljs-title function_">emitWarning</span>(<span class="hljs-string">'Only warn once!'</span>);
}
}
<span class="hljs-title function_">emitMyWarning</span>();
<span class="hljs-comment">// Emits: (node: 56339) Warning: Only warn once!</span>
<span class="hljs-title function_">emitMyWarning</span>();
<span class="hljs-comment">// Emits nothing</span></code><button class="copy-button">copy</button></pre>
</section><section><h3><code>process.env</code><span><a class="mark" href="#processenv" id="processenv">#</a></span><a aria-hidden="true" class="legacy" id="process_process_env"></a></h3>
<div class="api_metadata">
<details class="changelog"><summary>History</summary>
<table>
<tbody><tr><th>Version</th><th>Changes</th></tr>
<tr><td>v11.14.0</td>
<td><p>Worker threads will now use a copy of the parent thread's <code>process.env</code> by default, configurable through the <code>env</code> option of the <code>Worker</code> constructor.</p></td></tr>
<tr><td>v10.0.0</td>
<td><p>Implicit conversion of variable value to string is deprecated.</p></td></tr>
<tr><td>v0.1.27</td>
<td><p><span>Added in: v0.1.27</span></p></td></tr>
</tbody></table>
</details>
</div>
<ul>
<li><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object" class="type"><Object></a></li>
</ul>
<p>The <code>process.env</code> property returns an object containing the user environment.
See <a href="http://man7.org/linux/man-pages/man7/environ.7.html"><code>environ(7)</code></a>.</p>
<p>An example of this object looks like:</p>
<!-- eslint-skip -->
<pre><code class="language-js">{
<span class="hljs-attr">TERM</span>: <span class="hljs-string">'xterm-256color'</span>,
<span class="hljs-attr">SHELL</span>: <span class="hljs-string">'/usr/local/bin/bash'</span>,
<span class="hljs-attr">USER</span>: <span class="hljs-string">'maciej'</span>,
<span class="hljs-attr">PATH</span>: <span class="hljs-string">'~/.bin/:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin'</span>,
<span class="hljs-attr">PWD</span>: <span class="hljs-string">'/Users/maciej'</span>,
<span class="hljs-attr">EDITOR</span>: <span class="hljs-string">'vim'</span>,
<span class="hljs-attr">SHLVL</span>: <span class="hljs-string">'1'</span>,
<span class="hljs-attr">HOME</span>: <span class="hljs-string">'/Users/maciej'</span>,
<span class="hljs-attr">LOGNAME</span>: <span class="hljs-string">'maciej'</span>,
<span class="hljs-attr">_</span>: <span class="hljs-string">'/usr/local/bin/node'</span>
}</code> <button class="copy-button">copy</button></pre>
<p>It is possible to modify this object, but such modifications will not be
reflected outside the Node.js process, or (unless explicitly requested)
to other <a href="worker_threads.html#class-worker"><code>Worker</code></a> threads.
In other words, the following example would not work:</p>
<pre><code class="language-bash">node -e <span class="hljs-string">'process.env.foo = "bar"'</span> && <span class="hljs-built_in">echo</span> <span class="hljs-variable">$foo</span></code> <button class="copy-button">copy</button></pre>
<p>While the following will:</p>
<pre class="with-40-chars"><input class="js-flavor-toggle" type="checkbox" checked aria-label="Show modern ES modules syntax"><code class="language-js mjs"><span class="hljs-keyword">import</span> { env } <span class="hljs-keyword">from</span> <span class="hljs-string">'node:process'</span>;
env.<span class="hljs-property">foo</span> = <span class="hljs-string">'bar'</span>;
<span class="hljs-variable language_">console</span>.<span class="hljs-title function_">log</span>(env.<span class="hljs-property">foo</span>);</code><code class="language-js cjs"><span class="hljs-keyword">const</span> { env } = <span class="hljs-built_in">require</span>(<span class="hljs-string">'node:process'</span>);
env.<span class="hljs-property">foo</span> = <span class="hljs-string">'bar'</span>;
<span class="hljs-variable language_">console</span>.<span class="hljs-title function_">log</span>(env.<span class="hljs-property">foo</span>);</code><button class="copy-button">copy</button></pre>
<p>Assigning a property on <code>process.env</code> will implicitly convert the value
to a string. <strong>This behavior is deprecated.</strong> Future versions of Node.js may
throw an error when the value is not a string, number, or boolean.</p>
<pre class="with-40-chars"><input class="js-flavor-toggle" type="checkbox" checked aria-label="Show modern ES modules syntax"><code class="language-js mjs"><span class="hljs-keyword">import</span> { env } <span class="hljs-keyword">from</span> <span class="hljs-string">'node:process'</span>;
env.<span class="hljs-property">test</span> = <span class="hljs-literal">null</span>;
<span class="hljs-variable language_">console</span>.<span class="hljs-title function_">log</span>(env.<span class="hljs-property">test</span>);
<span class="hljs-comment">// => 'null'</span>
env.<span class="hljs-property">test</span> = <span class="hljs-literal">undefined</span>;
<span class="hljs-variable language_">console</span>.<span class="hljs-title function_">log</span>(env.<span class="hljs-property">test</span>);
<span class="hljs-comment">// => 'undefined'</span></code><code class="language-js cjs"><span class="hljs-keyword">const</span> { env } = <span class="hljs-built_in">require</span>(<span class="hljs-string">'node:process'</span>);
env.<span class="hljs-property">test</span> = <span class="hljs-literal">null</span>;
<span class="hljs-variable language_">console</span>.<span class="hljs-title function_">log</span>(env.<span class="hljs-property">test</span>);
<span class="hljs-comment">// => 'null'</span>
env.<span class="hljs-property">test</span> = <span class="hljs-literal">undefined</span>;
<span class="hljs-variable language_">console</span>.<span class="hljs-title function_">log</span>(env.<span class="hljs-property">test</span>);
<span class="hljs-comment">// => 'undefined'</span></code><button class="copy-button">copy</button></pre>
<p>Use <code>delete</code> to delete a property from <code>process.env</code>.</p>
<pre class="with-40-chars"><input class="js-flavor-toggle" type="checkbox" checked aria-label="Show modern ES modules syntax"><code class="language-js mjs"><span class="hljs-keyword">import</span> { env } <span class="hljs-keyword">from</span> <span class="hljs-string">'node:process'</span>;
env.<span class="hljs-property">TEST</span> = <span class="hljs-number">1</span>;
<span class="hljs-keyword">delete</span> env.<span class="hljs-property">TEST</span>;
<span class="hljs-variable language_">console</span>.<span class="hljs-title function_">log</span>(env.<span class="hljs-property">TEST</span>);
<span class="hljs-comment">// => undefined</span></code><code class="language-js cjs"><span class="hljs-keyword">const</span> { env } = <span class="hljs-built_in">require</span>(<span class="hljs-string">'node:process'</span>);
env.<span class="hljs-property">TEST</span> = <span class="hljs-number">1</span>;
<span class="hljs-keyword">delete</span> env.<span class="hljs-property">TEST</span>;
<span class="hljs-variable language_">console</span>.<span class="hljs-title function_">log</span>(env.<span class="hljs-property">TEST</span>);
<span class="hljs-comment">// => undefined</span></code><button class="copy-button">copy</button></pre>
<p>On Windows operating systems, environment variables are case-insensitive.</p>
<pre class="with-40-chars"><input class="js-flavor-toggle" type="checkbox" checked aria-label="Show modern ES modules syntax"><code class="language-js mjs"><span class="hljs-keyword">import</span> { env } <span class="hljs-keyword">from</span> <span class="hljs-string">'node:process'</span>;
env.<span class="hljs-property">TEST</span> = <span class="hljs-number">1</span>;
<span class="hljs-variable language_">console</span>.<span class="hljs-title function_">log</span>(env.<span class="hljs-property">test</span>);
<span class="hljs-comment">// => 1</span></code><code class="language-js cjs"><span class="hljs-keyword">const</span> { env } = <span class="hljs-built_in">require</span>(<span class="hljs-string">'node:process'</span>);
env.<span class="hljs-property">TEST</span> = <span class="hljs-number">1</span>;
<span class="hljs-variable language_">console</span>.<span class="hljs-title function_">log</span>(env.<span class="hljs-property">test</span>);
<span class="hljs-comment">// => 1</span></code><button class="copy-button">copy</button></pre>
<p>Unless explicitly specified when creating a <a href="worker_threads.html#class-worker"><code>Worker</code></a> instance,
each <a href="worker_threads.html#class-worker"><code>Worker</code></a> thread has its own copy of <code>process.env</code>, based on its
parent thread's <code>process.env</code>, or whatever was specified as the <code>env</code> option
to the <a href="worker_threads.html#class-worker"><code>Worker</code></a> constructor. Changes to <code>process.env</code> will not be visible
across <a href="worker_threads.html#class-worker"><code>Worker</code></a> threads, and only the main thread can make changes that
are visible to the operating system or to native add-ons. On Windows, a copy of
<code>process.env</code> on a <a href="worker_threads.html#class-worker"><code>Worker</code></a> instance operates in a case-sensitive manner
unlike the main thread.</p>
</section><section><h3><code>process.execArgv</code><span><a class="mark" href="#processexecargv" id="processexecargv">#</a></span><a aria-hidden="true" class="legacy" id="process_process_execargv"></a></h3>
<div class="api_metadata">
<span>Added in: v0.7.7</span>
</div>
<ul>
<li><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type"><string[]></a></li>
</ul>
<p>The <code>process.execArgv</code> property returns the set of Node.js-specific command-line
options passed when the Node.js process was launched. These options do not
appear in the array returned by the <a href="#processargv"><code>process.argv</code></a> property, and do not
include the Node.js executable, the name of the script, or any options following
the script name. These options are useful in order to spawn child processes with
the same execution environment as the parent.</p>
<pre><code class="language-bash">node --icu-data-dir=./foo --require ./bar.js script.js --version</code> <button class="copy-button">copy</button></pre>
<p>Results in <code>process.execArgv</code>:</p>
<pre><code class="language-json"><span class="hljs-punctuation">[</span><span class="hljs-string">"--icu-data-dir=./foo"</span><span class="hljs-punctuation">,</span> <span class="hljs-string">"--require"</span><span class="hljs-punctuation">,</span> <span class="hljs-string">"./bar.js"</span><span class="hljs-punctuation">]</span></code> <button class="copy-button">copy</button></pre>
<p>And <code>process.argv</code>:</p>
<!-- eslint-disable @stylistic/js/semi -->
<pre><code class="language-js">[<span class="hljs-string">'/usr/local/bin/node'</span>, <span class="hljs-string">'script.js'</span>, <span class="hljs-string">'--version'</span>]</code> <button class="copy-button">copy</button></pre>
<p>Refer to <a href="worker_threads.html#new-workerfilename-options"><code>Worker</code> constructor</a> for the detailed behavior of worker
threads with this property.</p>
</section><section><h3><code>process.execPath</code><span><a class="mark" href="#processexecpath" id="processexecpath">#</a></span><a aria-hidden="true" class="legacy" id="process_process_execpath"></a></h3>
<div class="api_metadata">
<span>Added in: v0.1.100</span>
</div>
<ul>
<li><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type"><string></a></li>
</ul>
<p>The <code>process.execPath</code> property returns the absolute pathname of the executable
that started the Node.js process. Symbolic links, if any, are resolved.</p>
<!-- eslint-disable @stylistic/js/semi -->
<pre><code class="language-js"><span class="hljs-string">'/usr/local/bin/node'</span></code> <button class="copy-button">copy</button></pre>
</section><section><h3><code>process.exit([code])</code><span><a class="mark" href="#processexitcode" id="processexitcode">#</a></span><a aria-hidden="true" class="legacy" id="process_process_exit_code"></a></h3>
<div class="api_metadata">
<details class="changelog"><summary>History</summary>
<table>
<tbody><tr><th>Version</th><th>Changes</th></tr>
<tr><td>v20.0.0</td>
<td><p>Only accepts a code of type number, or of type string if it represents an integer.</p></td></tr>
<tr><td>v0.1.13</td>
<td><p><span>Added in: v0.1.13</span></p></td></tr>
</tbody></table>
</details>
</div>
<ul>
<li><code>code</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type" class="type"><integer></a> | <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type"><string></a> | <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Null_type" class="type"><null></a> | <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Undefined_type" class="type"><undefined></a> The exit code. For string type, only
integer strings (e.g.,'1') are allowed. <strong>Default:</strong> <code>0</code>.</li>
</ul>
<p>The <code>process.exit()</code> method instructs Node.js to terminate the process
synchronously with an exit status of <code>code</code>. If <code>code</code> is omitted, exit uses
either the 'success' code <code>0</code> or the value of <code>process.exitCode</code> if it has been
set. Node.js will not terminate until all the <a href="#event-exit"><code>'exit'</code></a> event listeners are
called.</p>
<p>To exit with a 'failure' code:</p>
<pre class="with-41-chars"><input class="js-flavor-toggle" type="checkbox" checked aria-label="Show modern ES modules syntax"><code class="language-js mjs"><span class="hljs-keyword">import</span> { exit } <span class="hljs-keyword">from</span> <span class="hljs-string">'node:process'</span>;
<span class="hljs-title function_">exit</span>(<span class="hljs-number">1</span>);</code><code class="language-js cjs"><span class="hljs-keyword">const</span> { exit } = <span class="hljs-built_in">require</span>(<span class="hljs-string">'node:process'</span>);
<span class="hljs-title function_">exit</span>(<span class="hljs-number">1</span>);</code><button class="copy-button">copy</button></pre>
<p>The shell that executed Node.js should see the exit code as <code>1</code>.</p>
<p>Calling <code>process.exit()</code> will force the process to exit as quickly as possible
even if there are still asynchronous operations pending that have not yet
completed fully, including I/O operations to <code>process.stdout</code> and
<code>process.stderr</code>.</p>
<p>In most situations, it is not actually necessary to call <code>process.exit()</code>
explicitly. The Node.js process will exit on its own <em>if there is no additional
work pending</em> in the event loop. The <code>process.exitCode</code> property can be set to
tell the process which exit code to use when the process exits gracefully.</p>
<p>For instance, the following example illustrates a <em>misuse</em> of the
<code>process.exit()</code> method that could lead to data printed to stdout being
truncated and lost:</p>
<pre class="with-41-chars"><input class="js-flavor-toggle" type="checkbox" checked aria-label="Show modern ES modules syntax"><code class="language-js mjs"><span class="hljs-keyword">import</span> { exit } <span class="hljs-keyword">from</span> <span class="hljs-string">'node:process'</span>;
<span class="hljs-comment">// This is an example of what *not* to do:</span>
<span class="hljs-keyword">if</span> (<span class="hljs-title function_">someConditionNotMet</span>()) {
<span class="hljs-title function_">printUsageToStdout</span>();
<span class="hljs-title function_">exit</span>(<span class="hljs-number">1</span>);
}</code><code class="language-js cjs"><span class="hljs-keyword">const</span> { exit } = <span class="hljs-built_in">require</span>(<span class="hljs-string">'node:process'</span>);
<span class="hljs-comment">// This is an example of what *not* to do:</span>
<span class="hljs-keyword">if</span> (<span class="hljs-title function_">someConditionNotMet</span>()) {
<span class="hljs-title function_">printUsageToStdout</span>();
<span class="hljs-title function_">exit</span>(<span class="hljs-number">1</span>);
}</code><button class="copy-button">copy</button></pre>
<p>The reason this is problematic is because writes to <code>process.stdout</code> in Node.js
are sometimes <em>asynchronous</em> and may occur over multiple ticks of the Node.js
event loop. Calling <code>process.exit()</code>, however, forces the process to exit
<em>before</em> those additional writes to <code>stdout</code> can be performed.</p>
<p>Rather than calling <code>process.exit()</code> directly, the code <em>should</em> set the
<code>process.exitCode</code> and allow the process to exit naturally by avoiding
scheduling any additional work for the event loop:</p>
<pre class="with-40-chars"><input class="js-flavor-toggle" type="checkbox" checked aria-label="Show modern ES modules syntax"><code class="language-js mjs"><span class="hljs-keyword">import</span> process <span class="hljs-keyword">from</span> <span class="hljs-string">'node:process'</span>;
<span class="hljs-comment">// How to properly set the exit code while letting</span>
<span class="hljs-comment">// the process exit gracefully.</span>
<span class="hljs-keyword">if</span> (<span class="hljs-title function_">someConditionNotMet</span>()) {
<span class="hljs-title function_">printUsageToStdout</span>();
process.<span class="hljs-property">exitCode</span> = <span class="hljs-number">1</span>;
}</code><code class="language-js cjs"><span class="hljs-keyword">const</span> process = <span class="hljs-built_in">require</span>(<span class="hljs-string">'node:process'</span>);
<span class="hljs-comment">// How to properly set the exit code while letting</span>
<span class="hljs-comment">// the process exit gracefully.</span>
<span class="hljs-keyword">if</span> (<span class="hljs-title function_">someConditionNotMet</span>()) {
<span class="hljs-title function_">printUsageToStdout</span>();
process.<span class="hljs-property">exitCode</span> = <span class="hljs-number">1</span>;
}</code><button class="copy-button">copy</button></pre>
<p>If it is necessary to terminate the Node.js process due to an error condition,
throwing an <em>uncaught</em> error and allowing the process to terminate accordingly
is safer than calling <code>process.exit()</code>.</p>
<p>In <a href="worker_threads.html#class-worker"><code>Worker</code></a> threads, this function stops the current thread rather
than the current process.</p>
</section><section><h3><code>process.exitCode</code><span><a class="mark" href="#processexitcode_1" id="processexitcode_1">#</a></span><a aria-hidden="true" class="legacy" id="process_process_exitcode"></a></h3>
<div class="api_metadata">
<details class="changelog"><summary>History</summary>
<table>
<tbody><tr><th>Version</th><th>Changes</th></tr>
<tr><td>v20.0.0</td>
<td><p>Only accepts a code of type number, or of type string if it represents an integer.</p></td></tr>
<tr><td>v0.11.8</td>
<td><p><span>Added in: v0.11.8</span></p></td></tr>
</tbody></table>
</details>
</div>
<ul>
<li><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type" class="type"><integer></a> | <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type"><string></a> | <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Null_type" class="type"><null></a> | <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Undefined_type" class="type"><undefined></a> The exit code. For string type, only
integer strings (e.g.,'1') are allowed. <strong>Default:</strong> <code>undefined</code>.</li>
</ul>
<p>A number which will be the process exit code, when the process either
exits gracefully, or is exited via <a href="#processexitcode"><code>process.exit()</code></a> without specifying
a code.</p>
<p>Specifying a code to <a href="#processexitcode"><code>process.exit(code)</code></a> will override any
previous setting of <code>process.exitCode</code>.</p>
</section><section><h3><code>process.features.cached_builtins</code><span><a class="mark" href="#processfeaturescached_builtins" id="processfeaturescached_builtins">#</a></span><a aria-hidden="true" class="legacy" id="process_process_features_cached_builtins"></a></h3>
<div class="api_metadata">
<span>Added in: v12.0.0</span>
</div>
<ul>
<li><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Boolean_type" class="type"><boolean></a></li>
</ul>
<p>A boolean value that is <code>true</code> if the current Node.js build is caching builtin modules.</p>
</section><section><h3><code>process.features.debug</code><span><a class="mark" href="#processfeaturesdebug" id="processfeaturesdebug">#</a></span><a aria-hidden="true" class="legacy" id="process_process_features_debug"></a></h3>
<div class="api_metadata">
<span>Added in: v0.5.5</span>
</div>
<ul>
<li><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Boolean_type" class="type"><boolean></a></li>
</ul>
<p>A boolean value that is <code>true</code> if the current Node.js build is a debug build.</p>
</section><section><h3><code>process.features.inspector</code><span><a class="mark" href="#processfeaturesinspector" id="processfeaturesinspector">#</a></span><a aria-hidden="true" class="legacy" id="process_process_features_inspector"></a></h3>
<div class="api_metadata">
<span>Added in: v11.10.0</span>
</div>
<ul>
<li><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Boolean_type" class="type"><boolean></a></li>
</ul>
<p>A boolean value that is <code>true</code> if the current Node.js build includes the inspector.</p>
</section><section><h3><code>process.features.ipv6</code><span><a class="mark" href="#processfeaturesipv6" id="processfeaturesipv6">#</a></span><a aria-hidden="true" class="legacy" id="process_process_features_ipv6"></a></h3>
<div class="api_metadata">
<span>Added in: v0.5.3</span><span>Deprecated since: v22.13.0</span>
</div>
<p></p><div class="api_stability api_stability_0"><a href="documentation.html#stability-index">Stability: 0</a> - Deprecated. This property is always true, and any checks based on it are
redundant.</div><p></p>
<ul>
<li><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Boolean_type" class="type"><boolean></a></li>
</ul>
<p>A boolean value that is <code>true</code> if the current Node.js build includes support for IPv6.</p>
<p>Since all Node.js builds have IPv6 support, this value is always <code>true</code>.</p>
</section><section><h3><code>process.features.require_module</code><span><a class="mark" href="#processfeaturesrequire_module" id="processfeaturesrequire_module">#</a></span><a aria-hidden="true" class="legacy" id="process_process_features_require_module"></a></h3>
<div class="api_metadata">
<span>Added in: v22.10.0</span>
</div>
<ul>
<li><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Boolean_type" class="type"><boolean></a></li>
</ul>
<p>A boolean value that is <code>true</code> if the current Node.js build supports
<a href="modules.html#loading-ecmascript-modules-using-require">loading ECMAScript modules using <code>require()</code></a>.</p>
</section><section><h3><code>process.features.tls</code><span><a class="mark" href="#processfeaturestls" id="processfeaturestls">#</a></span><a aria-hidden="true" class="legacy" id="process_process_features_tls"></a></h3>
<div class="api_metadata">
<span>Added in: v0.5.3</span>
</div>
<ul>
<li><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Boolean_type" class="type"><boolean></a></li>
</ul>
<p>A boolean value that is <code>true</code> if the current Node.js build includes support for TLS.</p>
</section><section><h3><code>process.features.tls_alpn</code><span><a class="mark" href="#processfeaturestls_alpn" id="processfeaturestls_alpn">#</a></span><a aria-hidden="true" class="legacy" id="process_process_features_tls_alpn"></a></h3>
<div class="api_metadata">
<span>Added in: v4.8.0</span><span>Deprecated since: v22.13.0</span>
</div>
<p></p><div class="api_stability api_stability_0"><a href="documentation.html#stability-index">Stability: 0</a> - Deprecated. Use <code>process.features.tls</code> instead.</div><p></p>
<ul>
<li><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Boolean_type" class="type"><boolean></a></li>
</ul>
<p>A boolean value that is <code>true</code> if the current Node.js build includes support for ALPN in TLS.</p>
<p>In Node.js 11.0.0 and later versions, the OpenSSL dependencies feature unconditional ALPN support.
This value is therefore identical to that of <code>process.features.tls</code>.</p>
</section><section><h3><code>process.features.tls_ocsp</code><span><a class="mark" href="#processfeaturestls_ocsp" id="processfeaturestls_ocsp">#</a></span><a aria-hidden="true" class="legacy" id="process_process_features_tls_ocsp"></a></h3>
<div class="api_metadata">
<span>Added in: v0.11.13</span><span>Deprecated since: v22.13.0</span>
</div>
<p></p><div class="api_stability api_stability_0"><a href="documentation.html#stability-index">Stability: 0</a> - Deprecated. Use <code>process.features.tls</code> instead.</div><p></p>
<ul>
<li><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Boolean_type" class="type"><boolean></a></li>
</ul>
<p>A boolean value that is <code>true</code> if the current Node.js build includes support for OCSP in TLS.</p>
<p>In Node.js 11.0.0 and later versions, the OpenSSL dependencies feature unconditional OCSP support.
This value is therefore identical to that of <code>process.features.tls</code>.</p>
</section><section><h3><code>process.features.tls_sni</code><span><a class="mark" href="#processfeaturestls_sni" id="processfeaturestls_sni">#</a></span><a aria-hidden="true" class="legacy" id="process_process_features_tls_sni"></a></h3>
<div class="api_metadata">
<span>Added in: v0.5.3</span><span>Deprecated since: v22.13.0</span>
</div>
<p></p><div class="api_stability api_stability_0"><a href="documentation.html#stability-index">Stability: 0</a> - Deprecated. Use <code>process.features.tls</code> instead.</div><p></p>
<ul>
<li><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Boolean_type" class="type"><boolean></a></li>
</ul>
<p>A boolean value that is <code>true</code> if the current Node.js build includes support for SNI in TLS.</p>
<p>In Node.js 11.0.0 and later versions, the OpenSSL dependencies feature unconditional SNI support.
This value is therefore identical to that of <code>process.features.tls</code>.</p>
</section><section><h3><code>process.features.typescript</code><span><a class="mark" href="#processfeaturestypescript" id="processfeaturestypescript">#</a></span><a aria-hidden="true" class="legacy" id="process_process_features_typescript"></a></h3>
<div class="api_metadata">
<span>Added in: v22.10.0</span>
</div>
<p></p><div class="api_stability api_stability_1"><a href="documentation.html#stability-index">Stability: 1</a>.1 - Active development</div><p></p>
<ul>
<li><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Boolean_type" class="type"><boolean></a> | <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type"><string></a></li>
</ul>
<p>A value that is <code>"strip"</code> if Node.js is run with <code>--experimental-strip-types</code>,
<code>"transform"</code> if Node.js is run with <code>--experimental-transform-types</code>, and <code>false</code> otherwise.</p>
</section><section><h3><code>process.features.uv</code><span><a class="mark" href="#processfeaturesuv" id="processfeaturesuv">#</a></span><a aria-hidden="true" class="legacy" id="process_process_features_uv"></a></h3>
<div class="api_metadata">
<span>Added in: v0.5.3</span><span>Deprecated since: v22.13.0</span>
</div>
<p></p><div class="api_stability api_stability_0"><a href="documentation.html#stability-index">Stability: 0</a> - Deprecated. This property is always true, and any checks based on it are
redundant.</div><p></p>
<ul>
<li><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Boolean_type" class="type"><boolean></a></li>
</ul>
<p>A boolean value that is <code>true</code> if the current Node.js build includes support for libuv.</p>
<p>Since it's not possible to build Node.js without libuv, this value is always <code>true</code>.</p>
</section><section><h3><code>process.finalization.register(ref, callback)</code><span><a class="mark" href="#processfinalizationregisterref-callback" id="processfinalizationregisterref-callback">#</a></span><a aria-hidden="true" class="legacy" id="process_process_finalization_register_ref_callback"></a></h3>
<div class="api_metadata">
<span>Added in: v22.5.0</span>
</div>
<p></p><div class="api_stability api_stability_1"><a href="documentation.html#stability-index">Stability: 1</a>.1 - Active Development</div><p></p>
<ul>
<li><code>ref</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object" class="type"><Object></a> | <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function" class="type"><Function></a> The reference to the resource that is being tracked.</li>
<li><code>callback</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function" class="type"><Function></a> The callback function to be called when the resource
is finalized.
<ul>
<li><code>ref</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object" class="type"><Object></a> | <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function" class="type"><Function></a> The reference to the resource that is being tracked.</li>
<li><code>event</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type"><string></a> The event that triggered the finalization. Defaults to 'exit'.</li>
</ul>
</li>
</ul>
<p>This function registers a callback to be called when the process emits the <code>exit</code>
event if the <code>ref</code> object was not garbage collected. If the object <code>ref</code> was garbage collected
before the <code>exit</code> event is emitted, the callback will be removed from the finalization registry,
and it will not be called on process exit.</p>
<p>Inside the callback you can release the resources allocated by the <code>ref</code> object.
Be aware that all limitations applied to the <code>beforeExit</code> event are also applied to the <code>callback</code> function,
this means that there is a possibility that the callback will not be called under special circumstances.</p>
<p>The idea of ​​this function is to help you free up resources when the starts process exiting,
but also let the object be garbage collected if it is no longer being used.</p>
<p>Eg: you can register an object that contains a buffer, you want to make sure that buffer is released
when the process exit, but if the object is garbage collected before the process exit, we no longer
need to release the buffer, so in this case we just remove the callback from the finalization registry.</p>
<pre class="with-49-chars"><input class="js-flavor-toggle" type="checkbox" aria-label="Show modern ES modules syntax"><code class="language-js cjs"><span class="hljs-keyword">const</span> { finalization } = <span class="hljs-built_in">require</span>(<span class="hljs-string">'node:process'</span>);
<span class="hljs-comment">// Please make sure that the function passed to finalization.register()</span>
<span class="hljs-comment">// does not create a closure around unnecessary objects.</span>
<span class="hljs-keyword">function</span> <span class="hljs-title function_">onFinalize</span>(<span class="hljs-params">obj, event</span>) {
<span class="hljs-comment">// You can do whatever you want with the object</span>
obj.<span class="hljs-title function_">dispose</span>();
}
<span class="hljs-keyword">function</span> <span class="hljs-title function_">setup</span>(<span class="hljs-params"></span>) {
<span class="hljs-comment">// This object can be safely garbage collected,</span>
<span class="hljs-comment">// and the resulting shutdown function will not be called.</span>
<span class="hljs-comment">// There are no leaks.</span>
<span class="hljs-keyword">const</span> myDisposableObject = {
<span class="hljs-title function_">dispose</span>(<span class="hljs-params"></span>) {
<span class="hljs-comment">// Free your resources synchronously</span>
},
};
finalization.<span class="hljs-title function_">register</span>(myDisposableObject, onFinalize);
}
<span class="hljs-title function_">setup</span>();</code><code class="language-js mjs"><span class="hljs-keyword">import</span> { finalization } <span class="hljs-keyword">from</span> <span class="hljs-string">'node:process'</span>;
<span class="hljs-comment">// Please make sure that the function passed to finalization.register()</span>
<span class="hljs-comment">// does not create a closure around unnecessary objects.</span>
<span class="hljs-keyword">function</span> <span class="hljs-title function_">onFinalize</span>(<span class="hljs-params">obj, event</span>) {
<span class="hljs-comment">// You can do whatever you want with the object</span>
obj.<span class="hljs-title function_">dispose</span>();
}
<span class="hljs-keyword">function</span> <span class="hljs-title function_">setup</span>(<span class="hljs-params"></span>) {
<span class="hljs-comment">// This object can be safely garbage collected,</span>
<span class="hljs-comment">// and the resulting shutdown function will not be called.</span>
<span class="hljs-comment">// There are no leaks.</span>
<span class="hljs-keyword">const</span> myDisposableObject = {
<span class="hljs-title function_">dispose</span>(<span class="hljs-params"></span>) {
<span class="hljs-comment">// Free your resources synchronously</span>
},
};
finalization.<span class="hljs-title function_">register</span>(myDisposableObject, onFinalize);
}
<span class="hljs-title function_">setup</span>();</code><button class="copy-button">copy</button></pre>
<p>The code above relies on the following assumptions:</p>
<ul>
<li>arrow functions are avoided</li>
<li>regular functions are recommended to be within the global context (root)</li>
</ul>
<p>Regular functions <em>could</em> reference the context where the <code>obj</code> lives, making the <code>obj</code> not garbage collectible.</p>
<p>Arrow functions will hold the previous context. Consider, for example:</p>
<pre><code class="language-js"><span class="hljs-keyword">class</span> <span class="hljs-title class_">Test</span> {
<span class="hljs-title function_">constructor</span>(<span class="hljs-params"></span>) {
finalization.<span class="hljs-title function_">register</span>(<span class="hljs-variable language_">this</span>, <span class="hljs-function">(<span class="hljs-params">ref</span>) =></span> ref.<span class="hljs-title function_">dispose</span>());
<span class="hljs-comment">// Even something like this is highly discouraged</span>
<span class="hljs-comment">// finalization.register(this, () => this.dispose());</span>
}
<span class="hljs-title function_">dispose</span>(<span class="hljs-params"></span>) {}
}</code> <button class="copy-button">copy</button></pre>
<p>It is very unlikely (not impossible) that this object will be garbage collected,
but if it is not, <code>dispose</code> will be called when <code>process.exit</code> is called.</p>
<p>Be careful and avoid relying on this feature for the disposal of critical resources,
as it is not guaranteed that the callback will be called under all circumstances.</p>
</section><section><h3><code>process.finalization.registerBeforeExit(ref, callback)</code><span><a class="mark" href="#processfinalizationregisterbeforeexitref-callback" id="processfinalizationregisterbeforeexitref-callback">#</a></span><a aria-hidden="true" class="legacy" id="process_process_finalization_registerbeforeexit_ref_callback"></a></h3>
<div class="api_metadata">
<span>Added in: v22.5.0</span>
</div>
<p></p><div class="api_stability api_stability_1"><a href="documentation.html#stability-index">Stability: 1</a>.1 - Active Development</div><p></p>
<ul>
<li><code>ref</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object" class="type"><Object></a> | <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function" class="type"><Function></a> The reference
to the resource that is being tracked.</li>
<li><code>callback</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function" class="type"><Function></a> The callback function to be called when the resource
is finalized.
<ul>
<li><code>ref</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object" class="type"><Object></a> | <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function" class="type"><Function></a> The reference to the resource that is being tracked.</li>
<li><code>event</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type"><string></a> The event that triggered the finalization. Defaults to 'beforeExit'.</li>
</ul>
</li>
</ul>
<p>This function behaves exactly like the <code>register</code>, except that the callback will be called
when the process emits the <code>beforeExit</code> event if <code>ref</code> object was not garbage collected.</p>
<p>Be aware that all limitations applied to the <code>beforeExit</code> event are also applied to the <code>callback</code> function,
this means that there is a possibility that the callback will not be called under special circumstances.</p>
</section><section><h3><code>process.finalization.unregister(ref)</code><span><a class="mark" href="#processfinalizationunregisterref" id="processfinalizationunregisterref">#</a></span><a aria-hidden="true" class="legacy" id="process_process_finalization_unregister_ref"></a></h3>
<div class="api_metadata">
<span>Added in: v22.5.0</span>
</div>
<p></p><div class="api_stability api_stability_1"><a href="documentation.html#stability-index">Stability: 1</a>.1 - Active Development</div><p></p>
<ul>
<li><code>ref</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object" class="type"><Object></a> | <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function" class="type"><Function></a> The reference
to the resource that was registered previously.</li>
</ul>
<p>This function remove the register of the object from the finalization
registry, so the callback will not be called anymore.</p>
<pre class="with-49-chars"><input class="js-flavor-toggle" type="checkbox" aria-label="Show modern ES modules syntax"><code class="language-js cjs"><span class="hljs-keyword">const</span> { finalization } = <span class="hljs-built_in">require</span>(<span class="hljs-string">'node:process'</span>);
<span class="hljs-comment">// Please make sure that the function passed to finalization.register()</span>
<span class="hljs-comment">// does not create a closure around unnecessary objects.</span>
<span class="hljs-keyword">function</span> <span class="hljs-title function_">onFinalize</span>(<span class="hljs-params">obj, event</span>) {
<span class="hljs-comment">// You can do whatever you want with the object</span>
obj.<span class="hljs-title function_">dispose</span>();
}
<span class="hljs-keyword">function</span> <span class="hljs-title function_">setup</span>(<span class="hljs-params"></span>) {
<span class="hljs-comment">// This object can be safely garbage collected,</span>
<span class="hljs-comment">// and the resulting shutdown function will not be called.</span>
<span class="hljs-comment">// There are no leaks.</span>
<span class="hljs-keyword">const</span> myDisposableObject = {
<span class="hljs-title function_">dispose</span>(<span class="hljs-params"></span>) {
<span class="hljs-comment">// Free your resources synchronously</span>
},
};
finalization.<span class="hljs-title function_">register</span>(myDisposableObject, onFinalize);
<span class="hljs-comment">// Do something</span>
myDisposableObject.<span class="hljs-title function_">dispose</span>();
finalization.<span class="hljs-title function_">unregister</span>(myDisposableObject);
}
<span class="hljs-title function_">setup</span>();</code><code class="language-js mjs"><span class="hljs-keyword">import</span> { finalization } <span class="hljs-keyword">from</span> <span class="hljs-string">'node:process'</span>;
<span class="hljs-comment">// Please make sure that the function passed to finalization.register()</span>
<span class="hljs-comment">// does not create a closure around unnecessary objects.</span>
<span class="hljs-keyword">function</span> <span class="hljs-title function_">onFinalize</span>(<span class="hljs-params">obj, event</span>) {
<span class="hljs-comment">// You can do whatever you want with the object</span>
obj.<span class="hljs-title function_">dispose</span>();
}
<span class="hljs-keyword">function</span> <span class="hljs-title function_">setup</span>(<span class="hljs-params"></span>) {
<span class="hljs-comment">// This object can be safely garbage collected,</span>
<span class="hljs-comment">// and the resulting shutdown function will not be called.</span>
<span class="hljs-comment">// There are no leaks.</span>
<span class="hljs-keyword">const</span> myDisposableObject = {
<span class="hljs-title function_">dispose</span>(<span class="hljs-params"></span>) {
<span class="hljs-comment">// Free your resources synchronously</span>
},
};
<span class="hljs-comment">// Please make sure that the function passed to finalization.register()</span>
<span class="hljs-comment">// does not create a closure around unnecessary objects.</span>
<span class="hljs-keyword">function</span> <span class="hljs-title function_">onFinalize</span>(<span class="hljs-params">obj, event</span>) {
<span class="hljs-comment">// You can do whatever you want with the object</span>
obj.<span class="hljs-title function_">dispose</span>();
}
finalization.<span class="hljs-title function_">register</span>(myDisposableObject, onFinalize);
<span class="hljs-comment">// Do something</span>
myDisposableObject.<span class="hljs-title function_">dispose</span>();
finalization.<span class="hljs-title function_">unregister</span>(myDisposableObject);
}
<span class="hljs-title function_">setup</span>();</code><button class="copy-button">copy</button></pre>
</section><section><h3><code>process.getActiveResourcesInfo()</code><span><a class="mark" href="#processgetactiveresourcesinfo" id="processgetactiveresourcesinfo">#</a></span><a aria-hidden="true" class="legacy" id="process_process_getactiveresourcesinfo"></a></h3>
<div class="api_metadata">
<span>Added in: v17.3.0, v16.14.0</span>
</div>
<p></p><div class="api_stability api_stability_1"><a href="documentation.html#stability-index">Stability: 1</a> - Experimental</div><p></p>
<ul>
<li>Returns: <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type"><string[]></a></li>
</ul>
<p>The <code>process.getActiveResourcesInfo()</code> method returns an array of strings
containing the types of the active resources that are currently keeping the
event loop alive.</p>
<pre class="with-59-chars"><input class="js-flavor-toggle" type="checkbox" checked aria-label="Show modern ES modules syntax"><code class="language-js mjs"><span class="hljs-keyword">import</span> { getActiveResourcesInfo } <span class="hljs-keyword">from</span> <span class="hljs-string">'node:process'</span>;
<span class="hljs-keyword">import</span> { <span class="hljs-built_in">setTimeout</span> } <span class="hljs-keyword">from</span> <span class="hljs-string">'node:timers'</span>;
<span class="hljs-variable language_">console</span>.<span class="hljs-title function_">log</span>(<span class="hljs-string">'Before:'</span>, <span class="hljs-title function_">getActiveResourcesInfo</span>());
<span class="hljs-built_in">setTimeout</span>(<span class="hljs-function">() =></span> {}, <span class="hljs-number">1000</span>);
<span class="hljs-variable language_">console</span>.<span class="hljs-title function_">log</span>(<span class="hljs-string">'After:'</span>, <span class="hljs-title function_">getActiveResourcesInfo</span>());
<span class="hljs-comment">// Prints:</span>
<span class="hljs-comment">// Before: [ 'CloseReq', 'TTYWrap', 'TTYWrap', 'TTYWrap' ]</span>
<span class="hljs-comment">// After: [ 'CloseReq', 'TTYWrap', 'TTYWrap', 'TTYWrap', 'Timeout' ]</span></code><code class="language-js cjs"><span class="hljs-keyword">const</span> { getActiveResourcesInfo } = <span class="hljs-built_in">require</span>(<span class="hljs-string">'node:process'</span>);
<span class="hljs-keyword">const</span> { <span class="hljs-built_in">setTimeout</span> } = <span class="hljs-built_in">require</span>(<span class="hljs-string">'node:timers'</span>);
<span class="hljs-variable language_">console</span>.<span class="hljs-title function_">log</span>(<span class="hljs-string">'Before:'</span>, <span class="hljs-title function_">getActiveResourcesInfo</span>());
<span class="hljs-built_in">setTimeout</span>(<span class="hljs-function">() =></span> {}, <span class="hljs-number">1000</span>);
<span class="hljs-variable language_">console</span>.<span class="hljs-title function_">log</span>(<span class="hljs-string">'After:'</span>, <span class="hljs-title function_">getActiveResourcesInfo</span>());
<span class="hljs-comment">// Prints:</span>
<span class="hljs-comment">// Before: [ 'TTYWrap', 'TTYWrap', 'TTYWrap' ]</span>
<span class="hljs-comment">// After: [ 'TTYWrap', 'TTYWrap', 'TTYWrap', 'Timeout' ]</span></code><button class="copy-button">copy</button></pre>
</section><section><h3><code>process.getBuiltinModule(id)</code><span><a class="mark" href="#processgetbuiltinmoduleid" id="processgetbuiltinmoduleid">#</a></span><a aria-hidden="true" class="legacy" id="process_process_getbuiltinmodule_id"></a></h3>
<div class="api_metadata">
<span>Added in: v22.3.0</span>
</div>
<ul>
<li><code>id</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type"><string></a> ID of the built-in module being requested.</li>
<li>Returns: <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object" class="type"><Object></a> | <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Undefined_type" class="type"><undefined></a></li>
</ul>
<p><code>process.getBuiltinModule(id)</code> provides a way to load built-in modules
in a globally available function. ES Modules that need to support
other environments can use it to conditionally load a Node.js built-in
when it is run in Node.js, without having to deal with the resolution
error that can be thrown by <code>import</code> in a non-Node.js environment or
having to use dynamic <code>import()</code> which either turns the module into
an asynchronous module, or turns a synchronous API into an asynchronous one.</p>
<pre><code class="language-js mjs"><span class="hljs-keyword">if</span> (globalThis.<span class="hljs-property">process</span>?.<span class="hljs-property">getBuiltinModule</span>) {
<span class="hljs-comment">// Run in Node.js, use the Node.js fs module.</span>
<span class="hljs-keyword">const</span> fs = globalThis.<span class="hljs-property">process</span>.<span class="hljs-title function_">getBuiltinModule</span>(<span class="hljs-string">'fs'</span>);
<span class="hljs-comment">// If `require()` is needed to load user-modules, use createRequire()</span>
<span class="hljs-keyword">const</span> <span class="hljs-variable language_">module</span> = globalThis.<span class="hljs-property">process</span>.<span class="hljs-title function_">getBuiltinModule</span>(<span class="hljs-string">'module'</span>);
<span class="hljs-keyword">const</span> <span class="hljs-built_in">require</span> = <span class="hljs-variable language_">module</span>.<span class="hljs-title function_">createRequire</span>(<span class="hljs-keyword">import</span>.<span class="hljs-property">meta</span>.<span class="hljs-property">url</span>);
<span class="hljs-keyword">const</span> foo = <span class="hljs-built_in">require</span>(<span class="hljs-string">'foo'</span>);
}</code> <button class="copy-button">copy</button></pre>
<p>If <code>id</code> specifies a built-in module available in the current Node.js process,
<code>process.getBuiltinModule(id)</code> method returns the corresponding built-in
module. If <code>id</code> does not correspond to any built-in module, <code>undefined</code>
is returned.</p>
<p><code>process.getBuiltinModule(id)</code> accepts built-in module IDs that are recognized
by <a href="module.html#moduleisbuiltinmodulename"><code>module.isBuiltin(id)</code></a>. Some built-in modules must be loaded with the
<code>node:</code> prefix, see <a href="modules.html#built-in-modules-with-mandatory-node-prefix">built-in modules with mandatory <code>node:</code> prefix</a>.
The references returned by <code>process.getBuiltinModule(id)</code> always point to
the built-in module corresponding to <code>id</code> even if users modify
<a href="modules.html#requirecache"><code>require.cache</code></a> so that <code>require(id)</code> returns something else.</p>
</section><section><h3><code>process.getegid()</code><span><a class="mark" href="#processgetegid" id="processgetegid">#</a></span><a aria-hidden="true" class="legacy" id="process_process_getegid"></a></h3>
<div class="api_metadata">
<span>Added in: v2.0.0</span>
</div>
<p>The <code>process.getegid()</code> method returns the numerical effective group identity
of the Node.js process. (See <a href="http://man7.org/linux/man-pages/man2/getegid.2.html"><code>getegid(2)</code></a>.)</p>
<pre class="with-40-chars"><input class="js-flavor-toggle" type="checkbox" checked aria-label="Show modern ES modules syntax"><code class="language-js mjs"><span class="hljs-keyword">import</span> process <span class="hljs-keyword">from</span> <span class="hljs-string">'node:process'</span>;
<span class="hljs-keyword">if</span> (process.<span class="hljs-property">getegid</span>) {
<span class="hljs-variable language_">console</span>.<span class="hljs-title function_">log</span>(<span class="hljs-string">`Current gid: <span class="hljs-subst">${process.getegid()}</span>`</span>);
}</code><code class="language-js cjs"><span class="hljs-keyword">const</span> process = <span class="hljs-built_in">require</span>(<span class="hljs-string">'node:process'</span>);
<span class="hljs-keyword">if</span> (process.<span class="hljs-property">getegid</span>) {
<span class="hljs-variable language_">console</span>.<span class="hljs-title function_">log</span>(<span class="hljs-string">`Current gid: <span class="hljs-subst">${process.getegid()}</span>`</span>);
}</code><button class="copy-button">copy</button></pre>
<p>This function is only available on POSIX platforms (i.e. not Windows or
Android).</p>
</section><section><h3><code>process.geteuid()</code><span><a class="mark" href="#processgeteuid" id="processgeteuid">#</a></span><a aria-hidden="true" class="legacy" id="process_process_geteuid"></a></h3>
<div class="api_metadata">
<span>Added in: v2.0.0</span>
</div>
<ul>
<li>Returns: <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object" class="type"><Object></a></li>
</ul>
<p>The <code>process.geteuid()</code> method returns the numerical effective user identity of
the process. (See <a href="http://man7.org/linux/man-pages/man2/geteuid.2.html"><code>geteuid(2)</code></a>.)</p>
<pre class="with-40-chars"><input class="js-flavor-toggle" type="checkbox" checked aria-label="Show modern ES modules syntax"><code class="language-js mjs"><span class="hljs-keyword">import</span> process <span class="hljs-keyword">from</span> <span class="hljs-string">'node:process'</span>;
<span class="hljs-keyword">if</span> (process.<span class="hljs-property">geteuid</span>) {
<span class="hljs-variable language_">console</span>.<span class="hljs-title function_">log</span>(<span class="hljs-string">`Current uid: <span class="hljs-subst">${process.geteuid()}</span>`</span>);
}</code><code class="language-js cjs"><span class="hljs-keyword">const</span> process = <span class="hljs-built_in">require</span>(<span class="hljs-string">'node:process'</span>);
<span class="hljs-keyword">if</span> (process.<span class="hljs-property">geteuid</span>) {
<span class="hljs-variable language_">console</span>.<span class="hljs-title function_">log</span>(<span class="hljs-string">`Current uid: <span class="hljs-subst">${process.geteuid()}</span>`</span>);
}</code><button class="copy-button">copy</button></pre>
<p>This function is only available on POSIX platforms (i.e. not Windows or
Android).</p>
</section><section><h3><code>process.getgid()</code><span><a class="mark" href="#processgetgid" id="processgetgid">#</a></span><a aria-hidden="true" class="legacy" id="process_process_getgid"></a></h3>
<div class="api_metadata">
<span>Added in: v0.1.31</span>
</div>
<ul>
<li>Returns: <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object" class="type"><Object></a></li>
</ul>
<p>The <code>process.getgid()</code> method returns the numerical group identity of the
process. (See <a href="http://man7.org/linux/man-pages/man2/getgid.2.html"><code>getgid(2)</code></a>.)</p>
<pre class="with-40-chars"><input class="js-flavor-toggle" type="checkbox" checked aria-label="Show modern ES modules syntax"><code class="language-js mjs"><span class="hljs-keyword">import</span> process <span class="hljs-keyword">from</span> <span class="hljs-string">'node:process'</span>;
<span class="hljs-keyword">if</span> (process.<span class="hljs-property">getgid</span>) {
<span class="hljs-variable language_">console</span>.<span class="hljs-title function_">log</span>(<span class="hljs-string">`Current gid: <span class="hljs-subst">${process.getgid()}</span>`</span>);
}</code><code class="language-js cjs"><span class="hljs-keyword">const</span> process = <span class="hljs-built_in">require</span>(<span class="hljs-string">'node:process'</span>);
<span class="hljs-keyword">if</span> (process.<span class="hljs-property">getgid</span>) {
<span class="hljs-variable language_">console</span>.<span class="hljs-title function_">log</span>(<span class="hljs-string">`Current gid: <span class="hljs-subst">${process.getgid()}</span>`</span>);
}</code><button class="copy-button">copy</button></pre>
<p>This function is only available on POSIX platforms (i.e. not Windows or
Android).</p>
</section><section><h3><code>process.getgroups()</code><span><a class="mark" href="#processgetgroups" id="processgetgroups">#</a></span><a aria-hidden="true" class="legacy" id="process_process_getgroups"></a></h3>
<div class="api_metadata">
<span>Added in: v0.9.4</span>
</div>
<ul>
<li>Returns: <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type" class="type"><integer[]></a></li>
</ul>
<p>The <code>process.getgroups()</code> method returns an array with the supplementary group
IDs. POSIX leaves it unspecified if the effective group ID is included but
Node.js ensures it always is.</p>
<pre class="with-40-chars"><input class="js-flavor-toggle" type="checkbox" checked aria-label="Show modern ES modules syntax"><code class="language-js mjs"><span class="hljs-keyword">import</span> process <span class="hljs-keyword">from</span> <span class="hljs-string">'node:process'</span>;
<span class="hljs-keyword">if</span> (process.<span class="hljs-property">getgroups</span>) {
<span class="hljs-variable language_">console</span>.<span class="hljs-title function_">log</span>(process.<span class="hljs-title function_">getgroups</span>()); <span class="hljs-comment">// [ 16, 21, 297 ]</span>
}</code><code class="language-js cjs"><span class="hljs-keyword">const</span> process = <span class="hljs-built_in">require</span>(<span class="hljs-string">'node:process'</span>);
<span class="hljs-keyword">if</span> (process.<span class="hljs-property">getgroups</span>) {
<span class="hljs-variable language_">console</span>.<span class="hljs-title function_">log</span>(process.<span class="hljs-title function_">getgroups</span>()); <span class="hljs-comment">// [ 16, 21, 297 ]</span>
}</code><button class="copy-button">copy</button></pre>
<p>This function is only available on POSIX platforms (i.e. not Windows or
Android).</p>
</section><section><h3><code>process.getuid()</code><span><a class="mark" href="#processgetuid" id="processgetuid">#</a></span><a aria-hidden="true" class="legacy" id="process_process_getuid"></a></h3>
<div class="api_metadata">
<span>Added in: v0.1.28</span>
</div>
<ul>
<li>Returns: <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type" class="type"><integer></a></li>
</ul>
<p>The <code>process.getuid()</code> method returns the numeric user identity of the process.
(See <a href="http://man7.org/linux/man-pages/man2/getuid.2.html"><code>getuid(2)</code></a>.)</p>
<pre class="with-40-chars"><input class="js-flavor-toggle" type="checkbox" checked aria-label="Show modern ES modules syntax"><code class="language-js mjs"><span class="hljs-keyword">import</span> process <span class="hljs-keyword">from</span> <span class="hljs-string">'node:process'</span>;
<span class="hljs-keyword">if</span> (process.<span class="hljs-property">getuid</span>) {
<span class="hljs-variable language_">console</span>.<span class="hljs-title function_">log</span>(<span class="hljs-string">`Current uid: <span class="hljs-subst">${process.getuid()}</span>`</span>);
}</code><code class="language-js cjs"><span class="hljs-keyword">const</span> process = <span class="hljs-built_in">require</span>(<span class="hljs-string">'node:process'</span>);
<span class="hljs-keyword">if</span> (process.<span class="hljs-property">getuid</span>) {
<span class="hljs-variable language_">console</span>.<span class="hljs-title function_">log</span>(<span class="hljs-string">`Current uid: <span class="hljs-subst">${process.getuid()}</span>`</span>);
}</code><button class="copy-button">copy</button></pre>
<p>This function is only available on POSIX platforms (i.e. not Windows or
Android).</p>
</section><section><h3><code>process.hasUncaughtExceptionCaptureCallback()</code><span><a class="mark" href="#processhasuncaughtexceptioncapturecallback" id="processhasuncaughtexceptioncapturecallback">#</a></span><a aria-hidden="true" class="legacy" id="process_process_hasuncaughtexceptioncapturecallback"></a></h3>
<div class="api_metadata">
<span>Added in: v9.3.0</span>
</div>
<ul>
<li>Returns: <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Boolean_type" class="type"><boolean></a></li>
</ul>
<p>Indicates whether a callback has been set using
<a href="#processsetuncaughtexceptioncapturecallbackfn"><code>process.setUncaughtExceptionCaptureCallback()</code></a>.</p>
</section><section><h3><code>process.hrtime([time])</code><span><a class="mark" href="#processhrtimetime" id="processhrtimetime">#</a></span><a aria-hidden="true" class="legacy" id="process_process_hrtime_time"></a></h3>
<div class="api_metadata">
<span>Added in: v0.7.6</span>
</div>
<p></p><div class="api_stability api_stability_3"><a href="documentation.html#stability-index">Stability: 3</a> - Legacy. Use <a href="#processhrtimebigint"><code>process.hrtime.bigint()</code></a> instead.</div><p></p>
<ul>
<li><code>time</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type" class="type"><integer[]></a> The result of a previous call to <code>process.hrtime()</code></li>
<li>Returns: <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type" class="type"><integer[]></a></li>
</ul>
<p>This is the legacy version of <a href="#processhrtimebigint"><code>process.hrtime.bigint()</code></a>
before <code>bigint</code> was introduced in JavaScript.</p>
<p>The <code>process.hrtime()</code> method returns the current high-resolution real time
in a <code>[seconds, nanoseconds]</code> tuple <code>Array</code>, where <code>nanoseconds</code> is the
remaining part of the real time that can't be represented in second precision.</p>
<p><code>time</code> is an optional parameter that must be the result of a previous
<code>process.hrtime()</code> call to diff with the current time. If the parameter
passed in is not a tuple <code>Array</code>, a <code>TypeError</code> will be thrown. Passing in a
user-defined array instead of the result of a previous call to
<code>process.hrtime()</code> will lead to undefined behavior.</p>
<p>These times are relative to an arbitrary time in the
past, and not related to the time of day and therefore not subject to clock
drift. The primary use is for measuring performance between intervals:</p>
<pre class="with-43-chars"><input class="js-flavor-toggle" type="checkbox" checked aria-label="Show modern ES modules syntax"><code class="language-js mjs"><span class="hljs-keyword">import</span> { hrtime } <span class="hljs-keyword">from</span> <span class="hljs-string">'node:process'</span>;
<span class="hljs-keyword">const</span> <span class="hljs-variable constant_">NS_PER_SEC</span> = <span class="hljs-number">1e9</span>;
<span class="hljs-keyword">const</span> time = <span class="hljs-title function_">hrtime</span>();
<span class="hljs-comment">// [ 1800216, 25 ]</span>
<span class="hljs-built_in">setTimeout</span>(<span class="hljs-function">() =></span> {
<span class="hljs-keyword">const</span> diff = <span class="hljs-title function_">hrtime</span>(time);
<span class="hljs-comment">// [ 1, 552 ]</span>
<span class="hljs-variable language_">console</span>.<span class="hljs-title function_">log</span>(<span class="hljs-string">`Benchmark took <span class="hljs-subst">${diff[<span class="hljs-number">0</span>] * NS_PER_SEC + diff[<span class="hljs-number">1</span>]}</span> nanoseconds`</span>);
<span class="hljs-comment">// Benchmark took 1000000552 nanoseconds</span>
}, <span class="hljs-number">1000</span>);</code><code class="language-js cjs"><span class="hljs-keyword">const</span> { hrtime } = <span class="hljs-built_in">require</span>(<span class="hljs-string">'node:process'</span>);
<span class="hljs-keyword">const</span> <span class="hljs-variable constant_">NS_PER_SEC</span> = <span class="hljs-number">1e9</span>;
<span class="hljs-keyword">const</span> time = <span class="hljs-title function_">hrtime</span>();
<span class="hljs-comment">// [ 1800216, 25 ]</span>
<span class="hljs-built_in">setTimeout</span>(<span class="hljs-function">() =></span> {
<span class="hljs-keyword">const</span> diff = <span class="hljs-title function_">hrtime</span>(time);
<span class="hljs-comment">// [ 1, 552 ]</span>
<span class="hljs-variable language_">console</span>.<span class="hljs-title function_">log</span>(<span class="hljs-string">`Benchmark took <span class="hljs-subst">${diff[<span class="hljs-number">0</span>] * NS_PER_SEC + diff[<span class="hljs-number">1</span>]}</span> nanoseconds`</span>);
<span class="hljs-comment">// Benchmark took 1000000552 nanoseconds</span>
}, <span class="hljs-number">1000</span>);</code><button class="copy-button">copy</button></pre>
</section><section><h3><code>process.hrtime.bigint()</code><span><a class="mark" href="#processhrtimebigint" id="processhrtimebigint">#</a></span><a aria-hidden="true" class="legacy" id="process_process_hrtime_bigint"></a></h3>
<div class="api_metadata">
<span>Added in: v10.7.0</span>
</div>
<ul>
<li>Returns: <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/BigInt" class="type"><bigint></a></li>
</ul>
<p>The <code>bigint</code> version of the <a href="#processhrtimetime"><code>process.hrtime()</code></a> method returning the
current high-resolution real time in nanoseconds as a <code>bigint</code>.</p>
<p>Unlike <a href="#processhrtimetime"><code>process.hrtime()</code></a>, it does not support an additional <code>time</code>
argument since the difference can just be computed directly
by subtraction of the two <code>bigint</code>s.</p>
<pre class="with-43-chars"><input class="js-flavor-toggle" type="checkbox" checked aria-label="Show modern ES modules syntax"><code class="language-js mjs"><span class="hljs-keyword">import</span> { hrtime } <span class="hljs-keyword">from</span> <span class="hljs-string">'node:process'</span>;
<span class="hljs-keyword">const</span> start = hrtime.<span class="hljs-title function_">bigint</span>();
<span class="hljs-comment">// 191051479007711n</span>
<span class="hljs-built_in">setTimeout</span>(<span class="hljs-function">() =></span> {
<span class="hljs-keyword">const</span> end = hrtime.<span class="hljs-title function_">bigint</span>();
<span class="hljs-comment">// 191052633396993n</span>
<span class="hljs-variable language_">console</span>.<span class="hljs-title function_">log</span>(<span class="hljs-string">`Benchmark took <span class="hljs-subst">${end - start}</span> nanoseconds`</span>);
<span class="hljs-comment">// Benchmark took 1154389282 nanoseconds</span>
}, <span class="hljs-number">1000</span>);</code><code class="language-js cjs"><span class="hljs-keyword">const</span> { hrtime } = <span class="hljs-built_in">require</span>(<span class="hljs-string">'node:process'</span>);
<span class="hljs-keyword">const</span> start = hrtime.<span class="hljs-title function_">bigint</span>();
<span class="hljs-comment">// 191051479007711n</span>
<span class="hljs-built_in">setTimeout</span>(<span class="hljs-function">() =></span> {
<span class="hljs-keyword">const</span> end = hrtime.<span class="hljs-title function_">bigint</span>();
<span class="hljs-comment">// 191052633396993n</span>
<span class="hljs-variable language_">console</span>.<span class="hljs-title function_">log</span>(<span class="hljs-string">`Benchmark took <span class="hljs-subst">${end - start}</span> nanoseconds`</span>);
<span class="hljs-comment">// Benchmark took 1154389282 nanoseconds</span>
}, <span class="hljs-number">1000</span>);</code><button class="copy-button">copy</button></pre>
</section><section><h3><code>process.initgroups(user, extraGroup)</code><span><a class="mark" href="#processinitgroupsuser-extragroup" id="processinitgroupsuser-extragroup">#</a></span><a aria-hidden="true" class="legacy" id="process_process_initgroups_user_extragroup"></a></h3>
<div class="api_metadata">
<span>Added in: v0.9.4</span>
</div>
<ul>
<li><code>user</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type"><string></a> | <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type" class="type"><number></a> The user name or numeric identifier.</li>
<li><code>extraGroup</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type"><string></a> | <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type" class="type"><number></a> A group name or numeric identifier.</li>
</ul>
<p>The <code>process.initgroups()</code> method reads the <code>/etc/group</code> file and initializes
the group access list, using all groups of which the user is a member. This is
a privileged operation that requires that the Node.js process either have <code>root</code>
access or the <code>CAP_SETGID</code> capability.</p>
<p>Use care when dropping privileges:</p>
<pre class="with-66-chars"><input class="js-flavor-toggle" type="checkbox" checked aria-label="Show modern ES modules syntax"><code class="language-js mjs"><span class="hljs-keyword">import</span> { getgroups, initgroups, setgid } <span class="hljs-keyword">from</span> <span class="hljs-string">'node:process'</span>;
<span class="hljs-variable language_">console</span>.<span class="hljs-title function_">log</span>(<span class="hljs-title function_">getgroups</span>()); <span class="hljs-comment">// [ 0 ]</span>
<span class="hljs-title function_">initgroups</span>(<span class="hljs-string">'nodeuser'</span>, <span class="hljs-number">1000</span>); <span class="hljs-comment">// switch user</span>
<span class="hljs-variable language_">console</span>.<span class="hljs-title function_">log</span>(<span class="hljs-title function_">getgroups</span>()); <span class="hljs-comment">// [ 27, 30, 46, 1000, 0 ]</span>
<span class="hljs-title function_">setgid</span>(<span class="hljs-number">1000</span>); <span class="hljs-comment">// drop root gid</span>
<span class="hljs-variable language_">console</span>.<span class="hljs-title function_">log</span>(<span class="hljs-title function_">getgroups</span>()); <span class="hljs-comment">// [ 27, 30, 46, 1000 ]</span></code><code class="language-js cjs"><span class="hljs-keyword">const</span> { getgroups, initgroups, setgid } = <span class="hljs-built_in">require</span>(<span class="hljs-string">'node:process'</span>);
<span class="hljs-variable language_">console</span>.<span class="hljs-title function_">log</span>(<span class="hljs-title function_">getgroups</span>()); <span class="hljs-comment">// [ 0 ]</span>
<span class="hljs-title function_">initgroups</span>(<span class="hljs-string">'nodeuser'</span>, <span class="hljs-number">1000</span>); <span class="hljs-comment">// switch user</span>
<span class="hljs-variable language_">console</span>.<span class="hljs-title function_">log</span>(<span class="hljs-title function_">getgroups</span>()); <span class="hljs-comment">// [ 27, 30, 46, 1000, 0 ]</span>
<span class="hljs-title function_">setgid</span>(<span class="hljs-number">1000</span>); <span class="hljs-comment">// drop root gid</span>
<span class="hljs-variable language_">console</span>.<span class="hljs-title function_">log</span>(<span class="hljs-title function_">getgroups</span>()); <span class="hljs-comment">// [ 27, 30, 46, 1000 ]</span></code><button class="copy-button">copy</button></pre>
<p>This function is only available on POSIX platforms (i.e. not Windows or
Android).
This feature is not available in <a href="worker_threads.html#class-worker"><code>Worker</code></a> threads.</p>
</section><section><h3><code>process.kill(pid[, signal])</code><span><a class="mark" href="#processkillpid-signal" id="processkillpid-signal">#</a></span><a aria-hidden="true" class="legacy" id="process_process_kill_pid_signal"></a></h3>
<div class="api_metadata">
<span>Added in: v0.0.6</span>
</div>
<ul>
<li><code>pid</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type" class="type"><number></a> A process ID</li>
<li><code>signal</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type"><string></a> | <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type" class="type"><number></a> The signal to send, either as a string or number.
<strong>Default:</strong> <code>'SIGTERM'</code>.</li>
</ul>
<p>The <code>process.kill()</code> method sends the <code>signal</code> to the process identified by
<code>pid</code>.</p>
<p>Signal names are strings such as <code>'SIGINT'</code> or <code>'SIGHUP'</code>. See <a href="#signal-events">Signal Events</a>
and <a href="http://man7.org/linux/man-pages/man2/kill.2.html"><code>kill(2)</code></a> for more information.</p>
<p>This method will throw an error if the target <code>pid</code> does not exist. As a special
case, a signal of <code>0</code> can be used to test for the existence of a process.
Windows platforms will throw an error if the <code>pid</code> is used to kill a process
group.</p>
<p>Even though the name of this function is <code>process.kill()</code>, it is really just a
signal sender, like the <code>kill</code> system call. The signal sent may do something
other than kill the target process.</p>
<pre class="with-45-chars"><input class="js-flavor-toggle" type="checkbox" checked aria-label="Show modern ES modules syntax"><code class="language-js mjs"><span class="hljs-keyword">import</span> process, { kill } <span class="hljs-keyword">from</span> <span class="hljs-string">'node:process'</span>;
process.<span class="hljs-title function_">on</span>(<span class="hljs-string">'SIGHUP'</span>, <span class="hljs-function">() =></span> {
<span class="hljs-variable language_">console</span>.<span class="hljs-title function_">log</span>(<span class="hljs-string">'Got SIGHUP signal.'</span>);
});
<span class="hljs-built_in">setTimeout</span>(<span class="hljs-function">() =></span> {
<span class="hljs-variable language_">console</span>.<span class="hljs-title function_">log</span>(<span class="hljs-string">'Exiting.'</span>);
process.<span class="hljs-title function_">exit</span>(<span class="hljs-number">0</span>);
}, <span class="hljs-number">100</span>);
<span class="hljs-title function_">kill</span>(process.<span class="hljs-property">pid</span>, <span class="hljs-string">'SIGHUP'</span>);</code><code class="language-js cjs"><span class="hljs-keyword">const</span> process = <span class="hljs-built_in">require</span>(<span class="hljs-string">'node:process'</span>);
process.<span class="hljs-title function_">on</span>(<span class="hljs-string">'SIGHUP'</span>, <span class="hljs-function">() =></span> {
<span class="hljs-variable language_">console</span>.<span class="hljs-title function_">log</span>(<span class="hljs-string">'Got SIGHUP signal.'</span>);
});
<span class="hljs-built_in">setTimeout</span>(<span class="hljs-function">() =></span> {
<span class="hljs-variable language_">console</span>.<span class="hljs-title function_">log</span>(<span class="hljs-string">'Exiting.'</span>);
process.<span class="hljs-title function_">exit</span>(<span class="hljs-number">0</span>);
}, <span class="hljs-number">100</span>);
process.<span class="hljs-title function_">kill</span>(process.<span class="hljs-property">pid</span>, <span class="hljs-string">'SIGHUP'</span>);</code><button class="copy-button">copy</button></pre>
<p>When <code>SIGUSR1</code> is received by a Node.js process, Node.js will start the
debugger. See <a href="#signal-events">Signal Events</a>.</p>
</section><section><h3><code>process.loadEnvFile(path)</code><span><a class="mark" href="#processloadenvfilepath" id="processloadenvfilepath">#</a></span><a aria-hidden="true" class="legacy" id="process_process_loadenvfile_path"></a></h3>
<div class="api_metadata">
<span>Added in: v21.7.0, v20.12.0</span>
</div>
<p></p><div class="api_stability api_stability_1"><a href="documentation.html#stability-index">Stability: 1</a>.1 - Active development</div><p></p>
<ul>
<li><code>path</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type"><string></a> | <a href="url.html#the-whatwg-url-api" class="type"><URL></a> | <a href="buffer.html#class-buffer" class="type"><Buffer></a> | <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Undefined_type" class="type"><undefined></a>. <strong>Default:</strong> <code>'./.env'</code></li>
</ul>
<p>Loads the <code>.env</code> file into <code>process.env</code>. Usage of <code>NODE_OPTIONS</code>
in the <code>.env</code> file will not have any effect on Node.js.</p>
<pre class="with-48-chars"><input class="js-flavor-toggle" type="checkbox" aria-label="Show modern ES modules syntax"><code class="language-js cjs"><span class="hljs-keyword">const</span> { loadEnvFile } = <span class="hljs-built_in">require</span>(<span class="hljs-string">'node:process'</span>);
<span class="hljs-title function_">loadEnvFile</span>();</code><code class="language-js mjs"><span class="hljs-keyword">import</span> { loadEnvFile } <span class="hljs-keyword">from</span> <span class="hljs-string">'node:process'</span>;
<span class="hljs-title function_">loadEnvFile</span>();</code><button class="copy-button">copy</button></pre>
</section><section><h3><code>process.mainModule</code><span><a class="mark" href="#processmainmodule" id="processmainmodule">#</a></span><a aria-hidden="true" class="legacy" id="process_process_mainmodule"></a></h3>
<div class="api_metadata">
<span>Added in: v0.1.17</span><span>Deprecated since: v14.0.0</span>
</div>
<p></p><div class="api_stability api_stability_0"><a href="documentation.html#stability-index">Stability: 0</a> - Deprecated: Use <a href="modules.html#accessing-the-main-module"><code>require.main</code></a> instead.</div><p></p>
<ul>
<li><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object" class="type"><Object></a></li>
</ul>
<p>The <code>process.mainModule</code> property provides an alternative way of retrieving
<a href="modules.html#accessing-the-main-module"><code>require.main</code></a>. The difference is that if the main module changes at
runtime, <a href="modules.html#accessing-the-main-module"><code>require.main</code></a> may still refer to the original main module in
modules that were required before the change occurred. Generally, it's
safe to assume that the two refer to the same module.</p>
<p>As with <a href="modules.html#accessing-the-main-module"><code>require.main</code></a>, <code>process.mainModule</code> will be <code>undefined</code> if there
is no entry script.</p>
</section><section><h3><code>process.memoryUsage()</code><span><a class="mark" href="#processmemoryusage" id="processmemoryusage">#</a></span><a aria-hidden="true" class="legacy" id="process_process_memoryusage"></a></h3>
<div class="api_metadata">
<details class="changelog"><summary>History</summary>
<table>
<tbody><tr><th>Version</th><th>Changes</th></tr>
<tr><td>v13.9.0, v12.17.0</td>
<td><p>Added <code>arrayBuffers</code> to the returned object.</p></td></tr>
<tr><td>v7.2.0</td>
<td><p>Added <code>external</code> to the returned object.</p></td></tr>
<tr><td>v0.1.16</td>
<td><p><span>Added in: v0.1.16</span></p></td></tr>
</tbody></table>
</details>
</div>
<ul>
<li>Returns: <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object" class="type"><Object></a>
<ul>
<li><code>rss</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type" class="type"><integer></a></li>
<li><code>heapTotal</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type" class="type"><integer></a></li>
<li><code>heapUsed</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type" class="type"><integer></a></li>
<li><code>external</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type" class="type"><integer></a></li>
<li><code>arrayBuffers</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type" class="type"><integer></a></li>
</ul>
</li>
</ul>
<p>Returns an object describing the memory usage of the Node.js process measured in
bytes.</p>
<pre class="with-48-chars"><input class="js-flavor-toggle" type="checkbox" checked aria-label="Show modern ES modules syntax"><code class="language-js mjs"><span class="hljs-keyword">import</span> { memoryUsage } <span class="hljs-keyword">from</span> <span class="hljs-string">'node:process'</span>;
<span class="hljs-variable language_">console</span>.<span class="hljs-title function_">log</span>(<span class="hljs-title function_">memoryUsage</span>());
<span class="hljs-comment">// Prints:</span>
<span class="hljs-comment">// {</span>
<span class="hljs-comment">// rss: 4935680,</span>
<span class="hljs-comment">// heapTotal: 1826816,</span>
<span class="hljs-comment">// heapUsed: 650472,</span>
<span class="hljs-comment">// external: 49879,</span>
<span class="hljs-comment">// arrayBuffers: 9386</span>
<span class="hljs-comment">// }</span></code><code class="language-js cjs"><span class="hljs-keyword">const</span> { memoryUsage } = <span class="hljs-built_in">require</span>(<span class="hljs-string">'node:process'</span>);
<span class="hljs-variable language_">console</span>.<span class="hljs-title function_">log</span>(<span class="hljs-title function_">memoryUsage</span>());
<span class="hljs-comment">// Prints:</span>
<span class="hljs-comment">// {</span>
<span class="hljs-comment">// rss: 4935680,</span>
<span class="hljs-comment">// heapTotal: 1826816,</span>
<span class="hljs-comment">// heapUsed: 650472,</span>
<span class="hljs-comment">// external: 49879,</span>
<span class="hljs-comment">// arrayBuffers: 9386</span>
<span class="hljs-comment">// }</span></code><button class="copy-button">copy</button></pre>
<ul>
<li><code>heapTotal</code> and <code>heapUsed</code> refer to V8's memory usage.</li>
<li><code>external</code> refers to the memory usage of C++ objects bound to JavaScript
objects managed by V8.</li>
<li><code>rss</code>, Resident Set Size, is the amount of space occupied in the main
memory device (that is a subset of the total allocated memory) for the
process, including all C++ and JavaScript objects and code.</li>
<li><code>arrayBuffers</code> refers to memory allocated for <code>ArrayBuffer</code>s and
<code>SharedArrayBuffer</code>s, including all Node.js <a href="buffer.html"><code>Buffer</code></a>s.
This is also included in the <code>external</code> value. When Node.js is used as an
embedded library, this value may be <code>0</code> because allocations for <code>ArrayBuffer</code>s
may not be tracked in that case.</li>
</ul>
<p>When using <a href="worker_threads.html#class-worker"><code>Worker</code></a> threads, <code>rss</code> will be a value that is valid for the
entire process, while the other fields will only refer to the current thread.</p>
<p>The <code>process.memoryUsage()</code> method iterates over each page to gather
information about memory usage which might be slow depending on the
program memory allocations.</p>
</section><section><h3><code>process.memoryUsage.rss()</code><span><a class="mark" href="#processmemoryusagerss" id="processmemoryusagerss">#</a></span><a aria-hidden="true" class="legacy" id="process_process_memoryusage_rss"></a></h3>
<div class="api_metadata">
<span>Added in: v15.6.0, v14.18.0</span>
</div>
<ul>
<li>Returns: <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type" class="type"><integer></a></li>
</ul>
<p>The <code>process.memoryUsage.rss()</code> method returns an integer representing the
Resident Set Size (RSS) in bytes.</p>
<p>The Resident Set Size, is the amount of space occupied in the main
memory device (that is a subset of the total allocated memory) for the
process, including all C++ and JavaScript objects and code.</p>
<p>This is the same value as the <code>rss</code> property provided by <code>process.memoryUsage()</code>
but <code>process.memoryUsage.rss()</code> is faster.</p>
<pre class="with-48-chars"><input class="js-flavor-toggle" type="checkbox" checked aria-label="Show modern ES modules syntax"><code class="language-js mjs"><span class="hljs-keyword">import</span> { memoryUsage } <span class="hljs-keyword">from</span> <span class="hljs-string">'node:process'</span>;
<span class="hljs-variable language_">console</span>.<span class="hljs-title function_">log</span>(memoryUsage.<span class="hljs-title function_">rss</span>());
<span class="hljs-comment">// 35655680</span></code><code class="language-js cjs"><span class="hljs-keyword">const</span> { memoryUsage } = <span class="hljs-built_in">require</span>(<span class="hljs-string">'node:process'</span>);
<span class="hljs-variable language_">console</span>.<span class="hljs-title function_">log</span>(memoryUsage.<span class="hljs-title function_">rss</span>());
<span class="hljs-comment">// 35655680</span></code><button class="copy-button">copy</button></pre>
</section><section><h3><code>process.nextTick(callback[, ...args])</code><span><a class="mark" href="#processnexttickcallback-args" id="processnexttickcallback-args">#</a></span><a aria-hidden="true" class="legacy" id="process_process_nexttick_callback_args"></a></h3>
<div class="api_metadata">
<details class="changelog"><summary>History</summary>
<table>
<tbody><tr><th>Version</th><th>Changes</th></tr>
<tr><td>v22.7.0</td>
<td><p>Changed stability to Legacy.</p></td></tr>
<tr><td>v18.0.0</td>
<td><p>Passing an invalid callback to the <code>callback</code> argument now throws <code>ERR_INVALID_ARG_TYPE</code> instead of <code>ERR_INVALID_CALLBACK</code>.</p></td></tr>
<tr><td>v1.8.1</td>
<td><p>Additional arguments after <code>callback</code> are now supported.</p></td></tr>
<tr><td>v0.1.26</td>
<td><p><span>Added in: v0.1.26</span></p></td></tr>
</tbody></table>
</details>
</div>
<p></p><div class="api_stability api_stability_3"><a href="documentation.html#stability-index">Stability: 3</a> - Legacy: Use <a href="globals.html#queuemicrotaskcallback"><code>queueMicrotask()</code></a> instead.</div><p></p>
<ul>
<li><code>callback</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function" class="type"><Function></a></li>
<li><code>...args</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Data_types" class="type"><any></a> Additional arguments to pass when invoking the <code>callback</code></li>
</ul>
<p><code>process.nextTick()</code> adds <code>callback</code> to the "next tick queue". This queue is
fully drained after the current operation on the JavaScript stack runs to
completion and before the event loop is allowed to continue. It's possible to
create an infinite loop if one were to recursively call <code>process.nextTick()</code>.
See the <a href="https://nodejs.org/en/learn/asynchronous-work/event-loop-timers-and-nexttick#understanding-processnexttick">Event Loop</a> guide for more background.</p>
<pre class="with-45-chars"><input class="js-flavor-toggle" type="checkbox" checked aria-label="Show modern ES modules syntax"><code class="language-js mjs"><span class="hljs-keyword">import</span> { nextTick } <span class="hljs-keyword">from</span> <span class="hljs-string">'node:process'</span>;
<span class="hljs-variable language_">console</span>.<span class="hljs-title function_">log</span>(<span class="hljs-string">'start'</span>);
<span class="hljs-title function_">nextTick</span>(<span class="hljs-function">() =></span> {
<span class="hljs-variable language_">console</span>.<span class="hljs-title function_">log</span>(<span class="hljs-string">'nextTick callback'</span>);
});
<span class="hljs-variable language_">console</span>.<span class="hljs-title function_">log</span>(<span class="hljs-string">'scheduled'</span>);
<span class="hljs-comment">// Output:</span>
<span class="hljs-comment">// start</span>
<span class="hljs-comment">// scheduled</span>
<span class="hljs-comment">// nextTick callback</span></code><code class="language-js cjs"><span class="hljs-keyword">const</span> { nextTick } = <span class="hljs-built_in">require</span>(<span class="hljs-string">'node:process'</span>);
<span class="hljs-variable language_">console</span>.<span class="hljs-title function_">log</span>(<span class="hljs-string">'start'</span>);
<span class="hljs-title function_">nextTick</span>(<span class="hljs-function">() =></span> {
<span class="hljs-variable language_">console</span>.<span class="hljs-title function_">log</span>(<span class="hljs-string">'nextTick callback'</span>);
});
<span class="hljs-variable language_">console</span>.<span class="hljs-title function_">log</span>(<span class="hljs-string">'scheduled'</span>);
<span class="hljs-comment">// Output:</span>
<span class="hljs-comment">// start</span>
<span class="hljs-comment">// scheduled</span>
<span class="hljs-comment">// nextTick callback</span></code><button class="copy-button">copy</button></pre>
<p>This is important when developing APIs in order to give users the opportunity
to assign event handlers <em>after</em> an object has been constructed but before any
I/O has occurred:</p>
<pre class="with-45-chars"><input class="js-flavor-toggle" type="checkbox" checked aria-label="Show modern ES modules syntax"><code class="language-js mjs"><span class="hljs-keyword">import</span> { nextTick } <span class="hljs-keyword">from</span> <span class="hljs-string">'node:process'</span>;
<span class="hljs-keyword">function</span> <span class="hljs-title function_">MyThing</span>(<span class="hljs-params">options</span>) {
<span class="hljs-variable language_">this</span>.<span class="hljs-title function_">setupOptions</span>(options);
<span class="hljs-title function_">nextTick</span>(<span class="hljs-function">() =></span> {
<span class="hljs-variable language_">this</span>.<span class="hljs-title function_">startDoingStuff</span>();
});
}
<span class="hljs-keyword">const</span> thing = <span class="hljs-keyword">new</span> <span class="hljs-title class_">MyThing</span>();
thing.<span class="hljs-title function_">getReadyForStuff</span>();
<span class="hljs-comment">// thing.startDoingStuff() gets called now, not before.</span></code><code class="language-js cjs"><span class="hljs-keyword">const</span> { nextTick } = <span class="hljs-built_in">require</span>(<span class="hljs-string">'node:process'</span>);
<span class="hljs-keyword">function</span> <span class="hljs-title function_">MyThing</span>(<span class="hljs-params">options</span>) {
<span class="hljs-variable language_">this</span>.<span class="hljs-title function_">setupOptions</span>(options);
<span class="hljs-title function_">nextTick</span>(<span class="hljs-function">() =></span> {
<span class="hljs-variable language_">this</span>.<span class="hljs-title function_">startDoingStuff</span>();
});
}
<span class="hljs-keyword">const</span> thing = <span class="hljs-keyword">new</span> <span class="hljs-title class_">MyThing</span>();
thing.<span class="hljs-title function_">getReadyForStuff</span>();
<span class="hljs-comment">// thing.startDoingStuff() gets called now, not before.</span></code><button class="copy-button">copy</button></pre>
<p>It is very important for APIs to be either 100% synchronous or 100%
asynchronous. Consider this example:</p>
<pre><code class="language-js"><span class="hljs-comment">// WARNING! DO NOT USE! BAD UNSAFE HAZARD!</span>
<span class="hljs-keyword">function</span> <span class="hljs-title function_">maybeSync</span>(<span class="hljs-params">arg, cb</span>) {
<span class="hljs-keyword">if</span> (arg) {
<span class="hljs-title function_">cb</span>();
<span class="hljs-keyword">return</span>;
}
fs.<span class="hljs-title function_">stat</span>(<span class="hljs-string">'file'</span>, cb);
}</code> <button class="copy-button">copy</button></pre>
<p>This API is hazardous because in the following case:</p>
<pre><code class="language-js"><span class="hljs-keyword">const</span> maybeTrue = <span class="hljs-title class_">Math</span>.<span class="hljs-title function_">random</span>() > <span class="hljs-number">0.5</span>;
<span class="hljs-title function_">maybeSync</span>(maybeTrue, <span class="hljs-function">() =></span> {
<span class="hljs-title function_">foo</span>();
});
<span class="hljs-title function_">bar</span>();</code> <button class="copy-button">copy</button></pre>
<p>It is not clear whether <code>foo()</code> or <code>bar()</code> will be called first.</p>
<p>The following approach is much better:</p>
<pre class="with-45-chars"><input class="js-flavor-toggle" type="checkbox" checked aria-label="Show modern ES modules syntax"><code class="language-js mjs"><span class="hljs-keyword">import</span> { nextTick } <span class="hljs-keyword">from</span> <span class="hljs-string">'node:process'</span>;
<span class="hljs-keyword">function</span> <span class="hljs-title function_">definitelyAsync</span>(<span class="hljs-params">arg, cb</span>) {
<span class="hljs-keyword">if</span> (arg) {
<span class="hljs-title function_">nextTick</span>(cb);
<span class="hljs-keyword">return</span>;
}
fs.<span class="hljs-title function_">stat</span>(<span class="hljs-string">'file'</span>, cb);
}</code><code class="language-js cjs"><span class="hljs-keyword">const</span> { nextTick } = <span class="hljs-built_in">require</span>(<span class="hljs-string">'node:process'</span>);
<span class="hljs-keyword">function</span> <span class="hljs-title function_">definitelyAsync</span>(<span class="hljs-params">arg, cb</span>) {
<span class="hljs-keyword">if</span> (arg) {
<span class="hljs-title function_">nextTick</span>(cb);
<span class="hljs-keyword">return</span>;
}
fs.<span class="hljs-title function_">stat</span>(<span class="hljs-string">'file'</span>, cb);
}</code><button class="copy-button">copy</button></pre>
<h4>When to use <code>queueMicrotask()</code> vs. <code>process.nextTick()</code><span><a class="mark" href="#when-to-use-queuemicrotask-vs-processnexttick" id="when-to-use-queuemicrotask-vs-processnexttick">#</a></span><a aria-hidden="true" class="legacy" id="process_when_to_use_queuemicrotask_vs_process_nexttick"></a></h4>
<p>The <a href="globals.html#queuemicrotaskcallback"><code>queueMicrotask()</code></a> API is an alternative to <code>process.nextTick()</code> that instead of using the
"next tick queue" defers execution of a function using the same microtask queue used to execute the
then, catch, and finally handlers of resolved promises.</p>
<p>Within Node.js, every time the "next tick queue" is drained, the microtask queue
is drained immediately after.</p>
<p>So in CJS modules <code>process.nextTick()</code> callbacks are always run before <code>queueMicrotask()</code> ones.
However since ESM modules are processed already as part of the microtask queue, there
<code>queueMicrotask()</code> callbacks are always exectued before <code>process.nextTick()</code> ones since Node.js
is already in the process of draining the microtask queue.</p>
<pre class="with-45-chars"><input class="js-flavor-toggle" type="checkbox" checked aria-label="Show modern ES modules syntax"><code class="language-js mjs"><span class="hljs-keyword">import</span> { nextTick } <span class="hljs-keyword">from</span> <span class="hljs-string">'node:process'</span>;
<span class="hljs-title class_">Promise</span>.<span class="hljs-title function_">resolve</span>().<span class="hljs-title function_">then</span>(<span class="hljs-function">() =></span> <span class="hljs-variable language_">console</span>.<span class="hljs-title function_">log</span>(<span class="hljs-string">'resolve'</span>));
<span class="hljs-title function_">queueMicrotask</span>(<span class="hljs-function">() =></span> <span class="hljs-variable language_">console</span>.<span class="hljs-title function_">log</span>(<span class="hljs-string">'microtask'</span>));
<span class="hljs-title function_">nextTick</span>(<span class="hljs-function">() =></span> <span class="hljs-variable language_">console</span>.<span class="hljs-title function_">log</span>(<span class="hljs-string">'nextTick'</span>));
<span class="hljs-comment">// Output:</span>
<span class="hljs-comment">// resolve</span>
<span class="hljs-comment">// microtask</span>
<span class="hljs-comment">// nextTick</span></code><code class="language-js cjs"><span class="hljs-keyword">const</span> { nextTick } = <span class="hljs-built_in">require</span>(<span class="hljs-string">'node:process'</span>);
<span class="hljs-title class_">Promise</span>.<span class="hljs-title function_">resolve</span>().<span class="hljs-title function_">then</span>(<span class="hljs-function">() =></span> <span class="hljs-variable language_">console</span>.<span class="hljs-title function_">log</span>(<span class="hljs-string">'resolve'</span>));
<span class="hljs-title function_">queueMicrotask</span>(<span class="hljs-function">() =></span> <span class="hljs-variable language_">console</span>.<span class="hljs-title function_">log</span>(<span class="hljs-string">'microtask'</span>));
<span class="hljs-title function_">nextTick</span>(<span class="hljs-function">() =></span> <span class="hljs-variable language_">console</span>.<span class="hljs-title function_">log</span>(<span class="hljs-string">'nextTick'</span>));
<span class="hljs-comment">// Output:</span>
<span class="hljs-comment">// nextTick</span>
<span class="hljs-comment">// resolve</span>
<span class="hljs-comment">// microtask</span></code><button class="copy-button">copy</button></pre>
<p>For <em>most</em> userland use cases, the <code>queueMicrotask()</code> API provides a portable
and reliable mechanism for deferring execution that works across multiple
JavaScript platform environments and should be favored over <code>process.nextTick()</code>.
In simple scenarios, <code>queueMicrotask()</code> can be a drop-in replacement for
<code>process.nextTick()</code>.</p>
<pre><code class="language-js"><span class="hljs-variable language_">console</span>.<span class="hljs-title function_">log</span>(<span class="hljs-string">'start'</span>);
<span class="hljs-title function_">queueMicrotask</span>(<span class="hljs-function">() =></span> {
<span class="hljs-variable language_">console</span>.<span class="hljs-title function_">log</span>(<span class="hljs-string">'microtask callback'</span>);
});
<span class="hljs-variable language_">console</span>.<span class="hljs-title function_">log</span>(<span class="hljs-string">'scheduled'</span>);
<span class="hljs-comment">// Output:</span>
<span class="hljs-comment">// start</span>
<span class="hljs-comment">// scheduled</span>
<span class="hljs-comment">// microtask callback</span></code> <button class="copy-button">copy</button></pre>
<p>One note-worthy difference between the two APIs is that <code>process.nextTick()</code>
allows specifying additional values that will be passed as arguments to the
deferred function when it is called. Achieving the same result with
<code>queueMicrotask()</code> requires using either a closure or a bound function:</p>
<pre><code class="language-js"><span class="hljs-keyword">function</span> <span class="hljs-title function_">deferred</span>(<span class="hljs-params">a, b</span>) {
<span class="hljs-variable language_">console</span>.<span class="hljs-title function_">log</span>(<span class="hljs-string">'microtask'</span>, a + b);
}
<span class="hljs-variable language_">console</span>.<span class="hljs-title function_">log</span>(<span class="hljs-string">'start'</span>);
<span class="hljs-title function_">queueMicrotask</span>(deferred.<span class="hljs-title function_">bind</span>(<span class="hljs-literal">undefined</span>, <span class="hljs-number">1</span>, <span class="hljs-number">2</span>));
<span class="hljs-variable language_">console</span>.<span class="hljs-title function_">log</span>(<span class="hljs-string">'scheduled'</span>);
<span class="hljs-comment">// Output:</span>
<span class="hljs-comment">// start</span>
<span class="hljs-comment">// scheduled</span>
<span class="hljs-comment">// microtask 3</span></code> <button class="copy-button">copy</button></pre>
<p>There are minor differences in the way errors raised from within the next tick
queue and microtask queue are handled. Errors thrown within a queued microtask
callback should be handled within the queued callback when possible. If they are
not, the <code>process.on('uncaughtException')</code> event handler can be used to capture
and handle the errors.</p>
<p>When in doubt, unless the specific capabilities of <code>process.nextTick()</code> are
needed, use <code>queueMicrotask()</code>.</p>
</section><section><h3><code>process.noDeprecation</code><span><a class="mark" href="#processnodeprecation" id="processnodeprecation">#</a></span><a aria-hidden="true" class="legacy" id="process_process_nodeprecation"></a></h3>
<div class="api_metadata">
<span>Added in: v0.8.0</span>
</div>
<ul>
<li><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Boolean_type" class="type"><boolean></a></li>
</ul>
<p>The <code>process.noDeprecation</code> property indicates whether the <code>--no-deprecation</code>
flag is set on the current Node.js process. See the documentation for
the <a href="#event-warning"><code>'warning'</code> event</a> and the
<a href="#processemitwarningwarning-type-code-ctor"><code>emitWarning()</code> method</a> for more information about this
flag's behavior.</p>
</section><section><h3><code>process.permission</code><span><a class="mark" href="#processpermission" id="processpermission">#</a></span><a aria-hidden="true" class="legacy" id="process_process_permission"></a></h3>
<div class="api_metadata">
<span>Added in: v20.0.0</span>
</div>
<ul>
<li><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object" class="type"><Object></a></li>
</ul>
<p>This API is available through the <a href="cli.html#--permission"><code>--permission</code></a> flag.</p>
<p><code>process.permission</code> is an object whose methods are used to manage permissions
for the current process. Additional documentation is available in the
<a href="permissions.html#permission-model">Permission Model</a>.</p>
<h4><code>process.permission.has(scope[, reference])</code><span><a class="mark" href="#processpermissionhasscope-reference" id="processpermissionhasscope-reference">#</a></span><a aria-hidden="true" class="legacy" id="process_process_permission_has_scope_reference"></a></h4>
<div class="api_metadata">
<span>Added in: v20.0.0</span>
</div>
<ul>
<li><code>scope</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type"><string></a></li>
<li><code>reference</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type"><string></a></li>
<li>Returns: <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Boolean_type" class="type"><boolean></a></li>
</ul>
<p>Verifies that the process is able to access the given scope and reference.
If no reference is provided, a global scope is assumed, for instance,
<code>process.permission.has('fs.read')</code> will check if the process has ALL
file system read permissions.</p>
<p>The reference has a meaning based on the provided scope. For example,
the reference when the scope is File System means files and folders.</p>
<p>The available scopes are:</p>
<ul>
<li><code>fs</code> - All File System</li>
<li><code>fs.read</code> - File System read operations</li>
<li><code>fs.write</code> - File System write operations</li>
<li><code>child</code> - Child process spawning operations</li>
<li><code>worker</code> - Worker thread spawning operation</li>
</ul>
<pre><code class="language-js"><span class="hljs-comment">// Check if the process has permission to read the README file</span>
process.<span class="hljs-property">permission</span>.<span class="hljs-title function_">has</span>(<span class="hljs-string">'fs.read'</span>, <span class="hljs-string">'./README.md'</span>);
<span class="hljs-comment">// Check if the process has read permission operations</span>
process.<span class="hljs-property">permission</span>.<span class="hljs-title function_">has</span>(<span class="hljs-string">'fs.read'</span>);</code> <button class="copy-button">copy</button></pre>
</section><section><h3><code>process.pid</code><span><a class="mark" href="#processpid" id="processpid">#</a></span><a aria-hidden="true" class="legacy" id="process_process_pid"></a></h3>
<div class="api_metadata">
<span>Added in: v0.1.15</span>
</div>
<ul>
<li><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type" class="type"><integer></a></li>
</ul>
<p>The <code>process.pid</code> property returns the PID of the process.</p>
<pre class="with-40-chars"><input class="js-flavor-toggle" type="checkbox" checked aria-label="Show modern ES modules syntax"><code class="language-js mjs"><span class="hljs-keyword">import</span> { pid } <span class="hljs-keyword">from</span> <span class="hljs-string">'node:process'</span>;
<span class="hljs-variable language_">console</span>.<span class="hljs-title function_">log</span>(<span class="hljs-string">`This process is pid <span class="hljs-subst">${pid}</span>`</span>);</code><code class="language-js cjs"><span class="hljs-keyword">const</span> { pid } = <span class="hljs-built_in">require</span>(<span class="hljs-string">'node:process'</span>);
<span class="hljs-variable language_">console</span>.<span class="hljs-title function_">log</span>(<span class="hljs-string">`This process is pid <span class="hljs-subst">${pid}</span>`</span>);</code><button class="copy-button">copy</button></pre>
</section><section><h3><code>process.platform</code><span><a class="mark" href="#processplatform" id="processplatform">#</a></span><a aria-hidden="true" class="legacy" id="process_process_platform"></a></h3>
<div class="api_metadata">
<span>Added in: v0.1.16</span>
</div>
<ul>
<li><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type"><string></a></li>
</ul>
<p>The <code>process.platform</code> property returns a string identifying the operating
system platform for which the Node.js binary was compiled.</p>
<p>Currently possible values are:</p>
<ul>
<li><code>'aix'</code></li>
<li><code>'darwin'</code></li>
<li><code>'freebsd'</code></li>
<li><code>'linux'</code></li>
<li><code>'openbsd'</code></li>
<li><code>'sunos'</code></li>
<li><code>'win32'</code></li>
</ul>
<pre class="with-45-chars"><input class="js-flavor-toggle" type="checkbox" checked aria-label="Show modern ES modules syntax"><code class="language-js mjs"><span class="hljs-keyword">import</span> { platform } <span class="hljs-keyword">from</span> <span class="hljs-string">'node:process'</span>;
<span class="hljs-variable language_">console</span>.<span class="hljs-title function_">log</span>(<span class="hljs-string">`This platform is <span class="hljs-subst">${platform}</span>`</span>);</code><code class="language-js cjs"><span class="hljs-keyword">const</span> { platform } = <span class="hljs-built_in">require</span>(<span class="hljs-string">'node:process'</span>);
<span class="hljs-variable language_">console</span>.<span class="hljs-title function_">log</span>(<span class="hljs-string">`This platform is <span class="hljs-subst">${platform}</span>`</span>);</code><button class="copy-button">copy</button></pre>
<p>The value <code>'android'</code> may also be returned if the Node.js is built on the
Android operating system. However, Android support in Node.js
<a href="https://github.com/nodejs/node/blob/HEAD/BUILDING.md#android">is experimental</a>.</p>
</section><section><h3><code>process.ppid</code><span><a class="mark" href="#processppid" id="processppid">#</a></span><a aria-hidden="true" class="legacy" id="process_process_ppid"></a></h3>
<div class="api_metadata">
<span>Added in: v9.2.0, v8.10.0, v6.13.0</span>
</div>
<ul>
<li><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type" class="type"><integer></a></li>
</ul>
<p>The <code>process.ppid</code> property returns the PID of the parent of the
current process.</p>
<pre class="with-41-chars"><input class="js-flavor-toggle" type="checkbox" checked aria-label="Show modern ES modules syntax"><code class="language-js mjs"><span class="hljs-keyword">import</span> { ppid } <span class="hljs-keyword">from</span> <span class="hljs-string">'node:process'</span>;
<span class="hljs-variable language_">console</span>.<span class="hljs-title function_">log</span>(<span class="hljs-string">`The parent process is pid <span class="hljs-subst">${ppid}</span>`</span>);</code><code class="language-js cjs"><span class="hljs-keyword">const</span> { ppid } = <span class="hljs-built_in">require</span>(<span class="hljs-string">'node:process'</span>);
<span class="hljs-variable language_">console</span>.<span class="hljs-title function_">log</span>(<span class="hljs-string">`The parent process is pid <span class="hljs-subst">${ppid}</span>`</span>);</code><button class="copy-button">copy</button></pre>
</section><section><h3><code>process.ref(maybeRefable)</code><span><a class="mark" href="#processrefmayberefable" id="processrefmayberefable">#</a></span><a aria-hidden="true" class="legacy" id="process_process_ref_mayberefable"></a></h3>
<div class="api_metadata">
<span>Added in: v22.14.0</span>
</div>
<p></p><div class="api_stability api_stability_1"><a href="documentation.html#stability-index">Stability: 1</a> - Experimental</div><p></p>
<ul>
<li><code>maybeRefable</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Data_types" class="type"><any></a> An object that may be "refable".</li>
</ul>
<p>An object is "refable" if it implements the Node.js "Refable protocol".
Specifically, this means that the object implements the <code>Symbol.for('nodejs.ref')</code>
and <code>Symbol.for('nodejs.unref')</code> methods. "Ref'd" objects will keep the Node.js
event loop alive, while "unref'd" objects will not. Historically, this was
implemented by using <code>ref()</code> and <code>unref()</code> methods directly on the objects.
This pattern, however, is being deprecated in favor of the "Refable protocol"
in order to better support Web Platform API types whose APIs cannot be modified
to add <code>ref()</code> and <code>unref()</code> methods but still need to support that behavior.</p>
</section><section><h3><code>process.release</code><span><a class="mark" href="#processrelease" id="processrelease">#</a></span><a aria-hidden="true" class="legacy" id="process_process_release"></a></h3>
<div class="api_metadata">
<details class="changelog"><summary>History</summary>
<table>
<tbody><tr><th>Version</th><th>Changes</th></tr>
<tr><td>v4.2.0</td>
<td><p>The <code>lts</code> property is now supported.</p></td></tr>
<tr><td>v3.0.0</td>
<td><p><span>Added in: v3.0.0</span></p></td></tr>
</tbody></table>
</details>
</div>
<ul>
<li><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object" class="type"><Object></a></li>
</ul>
<p>The <code>process.release</code> property returns an <code>Object</code> containing metadata related
to the current release, including URLs for the source tarball and headers-only
tarball.</p>
<p><code>process.release</code> contains the following properties:</p>
<ul>
<li><code>name</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type"><string></a> A value that will always be <code>'node'</code>.</li>
<li><code>sourceUrl</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type"><string></a> an absolute URL pointing to a <em><code>.tar.gz</code></em> file containing
the source code of the current release.</li>
<li><code>headersUrl</code><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type"><string></a> an absolute URL pointing to a <em><code>.tar.gz</code></em> file containing
only the source header files for the current release. This file is
significantly smaller than the full source file and can be used for compiling
Node.js native add-ons.</li>
<li><code>libUrl</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type"><string></a> | <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Undefined_type" class="type"><undefined></a> an absolute URL pointing to a <em><code>node.lib</code></em> file
matching the architecture and version of the current release. This file is
used for compiling Node.js native add-ons. <em>This property is only present on
Windows builds of Node.js and will be missing on all other platforms.</em></li>
<li><code>lts</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type"><string></a> | <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Undefined_type" class="type"><undefined></a> a string label identifying the <a href="https://github.com/nodejs/Release">LTS</a> label for this
release. This property only exists for LTS releases and is <code>undefined</code> for all
other release types, including <em>Current</em> releases. Valid values include the
LTS Release code names (including those that are no longer supported).
<ul>
<li><code>'Fermium'</code> for the 14.x LTS line beginning with 14.15.0.</li>
<li><code>'Gallium'</code> for the 16.x LTS line beginning with 16.13.0.</li>
<li><code>'Hydrogen'</code> for the 18.x LTS line beginning with 18.12.0.
For other LTS Release code names, see <a href="https://github.com/nodejs/node/blob/HEAD/doc/changelogs/CHANGELOG_ARCHIVE.md">Node.js Changelog Archive</a></li>
</ul>
</li>
</ul>
<!-- eslint-skip -->
<pre><code class="language-js">{
<span class="hljs-attr">name</span>: <span class="hljs-string">'node'</span>,
<span class="hljs-attr">lts</span>: <span class="hljs-string">'Hydrogen'</span>,
<span class="hljs-attr">sourceUrl</span>: <span class="hljs-string">'https://nodejs.org/download/release/v18.12.0/node-v18.12.0.tar.gz'</span>,
<span class="hljs-attr">headersUrl</span>: <span class="hljs-string">'https://nodejs.org/download/release/v18.12.0/node-v18.12.0-headers.tar.gz'</span>,
<span class="hljs-attr">libUrl</span>: <span class="hljs-string">'https://nodejs.org/download/release/v18.12.0/win-x64/node.lib'</span>
}</code> <button class="copy-button">copy</button></pre>
<p>In custom builds from non-release versions of the source tree, only the
<code>name</code> property may be present. The additional properties should not be
relied upon to exist.</p>
</section><section><h3><code>process.report</code><span><a class="mark" href="#processreport" id="processreport">#</a></span><a aria-hidden="true" class="legacy" id="process_process_report"></a></h3>
<div class="api_metadata">
<details class="changelog"><summary>History</summary>
<table>
<tbody><tr><th>Version</th><th>Changes</th></tr>
<tr><td>v13.12.0, v12.17.0</td>
<td><p>This API is no longer experimental.</p></td></tr>
<tr><td>v11.8.0</td>
<td><p><span>Added in: v11.8.0</span></p></td></tr>
</tbody></table>
</details>
</div>
<ul>
<li><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object" class="type"><Object></a></li>
</ul>
<p><code>process.report</code> is an object whose methods are used to generate diagnostic
reports for the current process. Additional documentation is available in the
<a href="report.html">report documentation</a>.</p>
<h4><code>process.report.compact</code><span><a class="mark" href="#processreportcompact" id="processreportcompact">#</a></span><a aria-hidden="true" class="legacy" id="process_process_report_compact"></a></h4>
<div class="api_metadata">
<span>Added in: v13.12.0, v12.17.0</span>
</div>
<ul>
<li><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Boolean_type" class="type"><boolean></a></li>
</ul>
<p>Write reports in a compact format, single-line JSON, more easily consumable
by log processing systems than the default multi-line format designed for
human consumption.</p>
<pre class="with-43-chars"><input class="js-flavor-toggle" type="checkbox" checked aria-label="Show modern ES modules syntax"><code class="language-js mjs"><span class="hljs-keyword">import</span> { report } <span class="hljs-keyword">from</span> <span class="hljs-string">'node:process'</span>;
<span class="hljs-variable language_">console</span>.<span class="hljs-title function_">log</span>(<span class="hljs-string">`Reports are compact? <span class="hljs-subst">${report.compact}</span>`</span>);</code><code class="language-js cjs"><span class="hljs-keyword">const</span> { report } = <span class="hljs-built_in">require</span>(<span class="hljs-string">'node:process'</span>);
<span class="hljs-variable language_">console</span>.<span class="hljs-title function_">log</span>(<span class="hljs-string">`Reports are compact? <span class="hljs-subst">${report.compact}</span>`</span>);</code><button class="copy-button">copy</button></pre>
<h4><code>process.report.directory</code><span><a class="mark" href="#processreportdirectory" id="processreportdirectory">#</a></span><a aria-hidden="true" class="legacy" id="process_process_report_directory"></a></h4>
<div class="api_metadata">
<details class="changelog"><summary>History</summary>
<table>
<tbody><tr><th>Version</th><th>Changes</th></tr>
<tr><td>v13.12.0, v12.17.0</td>
<td><p>This API is no longer experimental.</p></td></tr>
<tr><td>v11.12.0</td>
<td><p><span>Added in: v11.12.0</span></p></td></tr>
</tbody></table>
</details>
</div>
<ul>
<li><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type"><string></a></li>
</ul>
<p>Directory where the report is written. The default value is the empty string,
indicating that reports are written to the current working directory of the
Node.js process.</p>
<pre class="with-43-chars"><input class="js-flavor-toggle" type="checkbox" checked aria-label="Show modern ES modules syntax"><code class="language-js mjs"><span class="hljs-keyword">import</span> { report } <span class="hljs-keyword">from</span> <span class="hljs-string">'node:process'</span>;
<span class="hljs-variable language_">console</span>.<span class="hljs-title function_">log</span>(<span class="hljs-string">`Report directory is <span class="hljs-subst">${report.directory}</span>`</span>);</code><code class="language-js cjs"><span class="hljs-keyword">const</span> { report } = <span class="hljs-built_in">require</span>(<span class="hljs-string">'node:process'</span>);
<span class="hljs-variable language_">console</span>.<span class="hljs-title function_">log</span>(<span class="hljs-string">`Report directory is <span class="hljs-subst">${report.directory}</span>`</span>);</code><button class="copy-button">copy</button></pre>
<h4><code>process.report.filename</code><span><a class="mark" href="#processreportfilename" id="processreportfilename">#</a></span><a aria-hidden="true" class="legacy" id="process_process_report_filename"></a></h4>
<div class="api_metadata">
<details class="changelog"><summary>History</summary>
<table>
<tbody><tr><th>Version</th><th>Changes</th></tr>
<tr><td>v13.12.0, v12.17.0</td>
<td><p>This API is no longer experimental.</p></td></tr>
<tr><td>v11.12.0</td>
<td><p><span>Added in: v11.12.0</span></p></td></tr>
</tbody></table>
</details>
</div>
<ul>
<li><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type"><string></a></li>
</ul>
<p>Filename where the report is written. If set to the empty string, the output
filename will be comprised of a timestamp, PID, and sequence number. The default
value is the empty string.</p>
<p>If the value of <code>process.report.filename</code> is set to <code>'stdout'</code> or <code>'stderr'</code>,
the report is written to the stdout or stderr of the process respectively.</p>
<pre class="with-43-chars"><input class="js-flavor-toggle" type="checkbox" checked aria-label="Show modern ES modules syntax"><code class="language-js mjs"><span class="hljs-keyword">import</span> { report } <span class="hljs-keyword">from</span> <span class="hljs-string">'node:process'</span>;
<span class="hljs-variable language_">console</span>.<span class="hljs-title function_">log</span>(<span class="hljs-string">`Report filename is <span class="hljs-subst">${report.filename}</span>`</span>);</code><code class="language-js cjs"><span class="hljs-keyword">const</span> { report } = <span class="hljs-built_in">require</span>(<span class="hljs-string">'node:process'</span>);
<span class="hljs-variable language_">console</span>.<span class="hljs-title function_">log</span>(<span class="hljs-string">`Report filename is <span class="hljs-subst">${report.filename}</span>`</span>);</code><button class="copy-button">copy</button></pre>
<h4><code>process.report.getReport([err])</code><span><a class="mark" href="#processreportgetreporterr" id="processreportgetreporterr">#</a></span><a aria-hidden="true" class="legacy" id="process_process_report_getreport_err"></a></h4>
<div class="api_metadata">
<details class="changelog"><summary>History</summary>
<table>
<tbody><tr><th>Version</th><th>Changes</th></tr>
<tr><td>v13.12.0, v12.17.0</td>
<td><p>This API is no longer experimental.</p></td></tr>
<tr><td>v11.8.0</td>
<td><p><span>Added in: v11.8.0</span></p></td></tr>
</tbody></table>
</details>
</div>
<ul>
<li><code>err</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Error" class="type"><Error></a> A custom error used for reporting the JavaScript stack.</li>
<li>Returns: <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object" class="type"><Object></a></li>
</ul>
<p>Returns a JavaScript Object representation of a diagnostic report for the
running process. The report's JavaScript stack trace is taken from <code>err</code>, if
present.</p>
<pre class="with-43-chars"><input class="js-flavor-toggle" type="checkbox" checked aria-label="Show modern ES modules syntax"><code class="language-js mjs"><span class="hljs-keyword">import</span> { report } <span class="hljs-keyword">from</span> <span class="hljs-string">'node:process'</span>;
<span class="hljs-keyword">import</span> util <span class="hljs-keyword">from</span> <span class="hljs-string">'node:util'</span>;
<span class="hljs-keyword">const</span> data = report.<span class="hljs-title function_">getReport</span>();
<span class="hljs-variable language_">console</span>.<span class="hljs-title function_">log</span>(data.<span class="hljs-property">header</span>.<span class="hljs-property">nodejsVersion</span>);
<span class="hljs-comment">// Similar to process.report.writeReport()</span>
<span class="hljs-keyword">import</span> fs <span class="hljs-keyword">from</span> <span class="hljs-string">'node:fs'</span>;
fs.<span class="hljs-title function_">writeFileSync</span>(<span class="hljs-string">'my-report.log'</span>, util.<span class="hljs-title function_">inspect</span>(data), <span class="hljs-string">'utf8'</span>);</code><code class="language-js cjs"><span class="hljs-keyword">const</span> { report } = <span class="hljs-built_in">require</span>(<span class="hljs-string">'node:process'</span>);
<span class="hljs-keyword">const</span> util = <span class="hljs-built_in">require</span>(<span class="hljs-string">'node:util'</span>);
<span class="hljs-keyword">const</span> data = report.<span class="hljs-title function_">getReport</span>();
<span class="hljs-variable language_">console</span>.<span class="hljs-title function_">log</span>(data.<span class="hljs-property">header</span>.<span class="hljs-property">nodejsVersion</span>);
<span class="hljs-comment">// Similar to process.report.writeReport()</span>
<span class="hljs-keyword">const</span> fs = <span class="hljs-built_in">require</span>(<span class="hljs-string">'node:fs'</span>);
fs.<span class="hljs-title function_">writeFileSync</span>(<span class="hljs-string">'my-report.log'</span>, util.<span class="hljs-title function_">inspect</span>(data), <span class="hljs-string">'utf8'</span>);</code><button class="copy-button">copy</button></pre>
<p>Additional documentation is available in the <a href="report.html">report documentation</a>.</p>
<h4><code>process.report.reportOnFatalError</code><span><a class="mark" href="#processreportreportonfatalerror" id="processreportreportonfatalerror">#</a></span><a aria-hidden="true" class="legacy" id="process_process_report_reportonfatalerror"></a></h4>
<div class="api_metadata">
<details class="changelog"><summary>History</summary>
<table>
<tbody><tr><th>Version</th><th>Changes</th></tr>
<tr><td>v15.0.0, v14.17.0</td>
<td><p>This API is no longer experimental.</p></td></tr>
<tr><td>v11.12.0</td>
<td><p><span>Added in: v11.12.0</span></p></td></tr>
</tbody></table>
</details>
</div>
<ul>
<li><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Boolean_type" class="type"><boolean></a></li>
</ul>
<p>If <code>true</code>, a diagnostic report is generated on fatal errors, such as out of
memory errors or failed C++ assertions.</p>
<pre class="with-43-chars"><input class="js-flavor-toggle" type="checkbox" checked aria-label="Show modern ES modules syntax"><code class="language-js mjs"><span class="hljs-keyword">import</span> { report } <span class="hljs-keyword">from</span> <span class="hljs-string">'node:process'</span>;
<span class="hljs-variable language_">console</span>.<span class="hljs-title function_">log</span>(<span class="hljs-string">`Report on fatal error: <span class="hljs-subst">${report.reportOnFatalError}</span>`</span>);</code><code class="language-js cjs"><span class="hljs-keyword">const</span> { report } = <span class="hljs-built_in">require</span>(<span class="hljs-string">'node:process'</span>);
<span class="hljs-variable language_">console</span>.<span class="hljs-title function_">log</span>(<span class="hljs-string">`Report on fatal error: <span class="hljs-subst">${report.reportOnFatalError}</span>`</span>);</code><button class="copy-button">copy</button></pre>
<h4><code>process.report.reportOnSignal</code><span><a class="mark" href="#processreportreportonsignal" id="processreportreportonsignal">#</a></span><a aria-hidden="true" class="legacy" id="process_process_report_reportonsignal"></a></h4>
<div class="api_metadata">
<details class="changelog"><summary>History</summary>
<table>
<tbody><tr><th>Version</th><th>Changes</th></tr>
<tr><td>v13.12.0, v12.17.0</td>
<td><p>This API is no longer experimental.</p></td></tr>
<tr><td>v11.12.0</td>
<td><p><span>Added in: v11.12.0</span></p></td></tr>
</tbody></table>
</details>
</div>
<ul>
<li><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Boolean_type" class="type"><boolean></a></li>
</ul>
<p>If <code>true</code>, a diagnostic report is generated when the process receives the
signal specified by <code>process.report.signal</code>.</p>
<pre class="with-43-chars"><input class="js-flavor-toggle" type="checkbox" checked aria-label="Show modern ES modules syntax"><code class="language-js mjs"><span class="hljs-keyword">import</span> { report } <span class="hljs-keyword">from</span> <span class="hljs-string">'node:process'</span>;
<span class="hljs-variable language_">console</span>.<span class="hljs-title function_">log</span>(<span class="hljs-string">`Report on signal: <span class="hljs-subst">${report.reportOnSignal}</span>`</span>);</code><code class="language-js cjs"><span class="hljs-keyword">const</span> { report } = <span class="hljs-built_in">require</span>(<span class="hljs-string">'node:process'</span>);
<span class="hljs-variable language_">console</span>.<span class="hljs-title function_">log</span>(<span class="hljs-string">`Report on signal: <span class="hljs-subst">${report.reportOnSignal}</span>`</span>);</code><button class="copy-button">copy</button></pre>
<h4><code>process.report.reportOnUncaughtException</code><span><a class="mark" href="#processreportreportonuncaughtexception" id="processreportreportonuncaughtexception">#</a></span><a aria-hidden="true" class="legacy" id="process_process_report_reportonuncaughtexception"></a></h4>
<div class="api_metadata">
<details class="changelog"><summary>History</summary>
<table>
<tbody><tr><th>Version</th><th>Changes</th></tr>
<tr><td>v13.12.0, v12.17.0</td>
<td><p>This API is no longer experimental.</p></td></tr>
<tr><td>v11.12.0</td>
<td><p><span>Added in: v11.12.0</span></p></td></tr>
</tbody></table>
</details>
</div>
<ul>
<li><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Boolean_type" class="type"><boolean></a></li>
</ul>
<p>If <code>true</code>, a diagnostic report is generated on uncaught exception.</p>
<pre class="with-43-chars"><input class="js-flavor-toggle" type="checkbox" checked aria-label="Show modern ES modules syntax"><code class="language-js mjs"><span class="hljs-keyword">import</span> { report } <span class="hljs-keyword">from</span> <span class="hljs-string">'node:process'</span>;
<span class="hljs-variable language_">console</span>.<span class="hljs-title function_">log</span>(<span class="hljs-string">`Report on exception: <span class="hljs-subst">${report.reportOnUncaughtException}</span>`</span>);</code><code class="language-js cjs"><span class="hljs-keyword">const</span> { report } = <span class="hljs-built_in">require</span>(<span class="hljs-string">'node:process'</span>);
<span class="hljs-variable language_">console</span>.<span class="hljs-title function_">log</span>(<span class="hljs-string">`Report on exception: <span class="hljs-subst">${report.reportOnUncaughtException}</span>`</span>);</code><button class="copy-button">copy</button></pre>
<h4><code>process.report.excludeEnv</code><span><a class="mark" href="#processreportexcludeenv" id="processreportexcludeenv">#</a></span><a aria-hidden="true" class="legacy" id="process_process_report_excludeenv"></a></h4>
<div class="api_metadata">
<span>Added in: v22.13.0</span>
</div>
<ul>
<li><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Boolean_type" class="type"><boolean></a></li>
</ul>
<p>If <code>true</code>, a diagnostic report is generated without the environment variables.</p>
<h4><code>process.report.signal</code><span><a class="mark" href="#processreportsignal" id="processreportsignal">#</a></span><a aria-hidden="true" class="legacy" id="process_process_report_signal"></a></h4>
<div class="api_metadata">
<details class="changelog"><summary>History</summary>
<table>
<tbody><tr><th>Version</th><th>Changes</th></tr>
<tr><td>v13.12.0, v12.17.0</td>
<td><p>This API is no longer experimental.</p></td></tr>
<tr><td>v11.12.0</td>
<td><p><span>Added in: v11.12.0</span></p></td></tr>
</tbody></table>
</details>
</div>
<ul>
<li><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type"><string></a></li>
</ul>
<p>The signal used to trigger the creation of a diagnostic report. Defaults to
<code>'SIGUSR2'</code>.</p>
<pre class="with-43-chars"><input class="js-flavor-toggle" type="checkbox" checked aria-label="Show modern ES modules syntax"><code class="language-js mjs"><span class="hljs-keyword">import</span> { report } <span class="hljs-keyword">from</span> <span class="hljs-string">'node:process'</span>;
<span class="hljs-variable language_">console</span>.<span class="hljs-title function_">log</span>(<span class="hljs-string">`Report signal: <span class="hljs-subst">${report.signal}</span>`</span>);</code><code class="language-js cjs"><span class="hljs-keyword">const</span> { report } = <span class="hljs-built_in">require</span>(<span class="hljs-string">'node:process'</span>);
<span class="hljs-variable language_">console</span>.<span class="hljs-title function_">log</span>(<span class="hljs-string">`Report signal: <span class="hljs-subst">${report.signal}</span>`</span>);</code><button class="copy-button">copy</button></pre>
<h4><code>process.report.writeReport([filename][, err])</code><span><a class="mark" href="#processreportwritereportfilename-err" id="processreportwritereportfilename-err">#</a></span><a aria-hidden="true" class="legacy" id="process_process_report_writereport_filename_err"></a></h4>
<div class="api_metadata">
<details class="changelog"><summary>History</summary>
<table>
<tbody><tr><th>Version</th><th>Changes</th></tr>
<tr><td>v13.12.0, v12.17.0</td>
<td><p>This API is no longer experimental.</p></td></tr>
<tr><td>v11.8.0</td>
<td><p><span>Added in: v11.8.0</span></p></td></tr>
</tbody></table>
</details>
</div>
<ul>
<li>
<p><code>filename</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type"><string></a> Name of the file where the report is written. This
should be a relative path, that will be appended to the directory specified in
<code>process.report.directory</code>, or the current working directory of the Node.js
process, if unspecified.</p>
</li>
<li>
<p><code>err</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Error" class="type"><Error></a> A custom error used for reporting the JavaScript stack.</p>
</li>
<li>
<p>Returns: <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type"><string></a> Returns the filename of the generated report.</p>
</li>
</ul>
<p>Writes a diagnostic report to a file. If <code>filename</code> is not provided, the default
filename includes the date, time, PID, and a sequence number. The report's
JavaScript stack trace is taken from <code>err</code>, if present.</p>
<p>If the value of <code>filename</code> is set to <code>'stdout'</code> or <code>'stderr'</code>, the report is
written to the stdout or stderr of the process respectively.</p>
<pre class="with-43-chars"><input class="js-flavor-toggle" type="checkbox" checked aria-label="Show modern ES modules syntax"><code class="language-js mjs"><span class="hljs-keyword">import</span> { report } <span class="hljs-keyword">from</span> <span class="hljs-string">'node:process'</span>;
report.<span class="hljs-title function_">writeReport</span>();</code><code class="language-js cjs"><span class="hljs-keyword">const</span> { report } = <span class="hljs-built_in">require</span>(<span class="hljs-string">'node:process'</span>);
report.<span class="hljs-title function_">writeReport</span>();</code><button class="copy-button">copy</button></pre>
<p>Additional documentation is available in the <a href="report.html">report documentation</a>.</p>
</section><section><h3><code>process.resourceUsage()</code><span><a class="mark" href="#processresourceusage" id="processresourceusage">#</a></span><a aria-hidden="true" class="legacy" id="process_process_resourceusage"></a></h3>
<div class="api_metadata">
<span>Added in: v12.6.0</span>
</div>
<ul>
<li>Returns: <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object" class="type"><Object></a> the resource usage for the current process. All of these
values come from the <code>uv_getrusage</code> call which returns
a <a href="https://docs.libuv.org/en/v1.x/misc.html#c.uv_rusage_t"><code>uv_rusage_t</code> struct</a>.
<ul>
<li><code>userCPUTime</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type" class="type"><integer></a> maps to <code>ru_utime</code> computed in microseconds.
It is the same value as <a href="#processcpuusagepreviousvalue"><code>process.cpuUsage().user</code></a>.</li>
<li><code>systemCPUTime</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type" class="type"><integer></a> maps to <code>ru_stime</code> computed in microseconds.
It is the same value as <a href="#processcpuusagepreviousvalue"><code>process.cpuUsage().system</code></a>.</li>
<li><code>maxRSS</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type" class="type"><integer></a> maps to <code>ru_maxrss</code> which is the maximum resident set
size used in kilobytes.</li>
<li><code>sharedMemorySize</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type" class="type"><integer></a> maps to <code>ru_ixrss</code> but is not supported by
any platform.</li>
<li><code>unsharedDataSize</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type" class="type"><integer></a> maps to <code>ru_idrss</code> but is not supported by
any platform.</li>
<li><code>unsharedStackSize</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type" class="type"><integer></a> maps to <code>ru_isrss</code> but is not supported by
any platform.</li>
<li><code>minorPageFault</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type" class="type"><integer></a> maps to <code>ru_minflt</code> which is the number of
minor page faults for the process, see
<a href="https://en.wikipedia.org/wiki/Page_fault#Minor">this article for more details</a>.</li>
<li><code>majorPageFault</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type" class="type"><integer></a> maps to <code>ru_majflt</code> which is the number of
major page faults for the process, see
<a href="https://en.wikipedia.org/wiki/Page_fault#Major">this article for more details</a>. This field is not
supported on Windows.</li>
<li><code>swappedOut</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type" class="type"><integer></a> maps to <code>ru_nswap</code> but is not supported by any
platform.</li>
<li><code>fsRead</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type" class="type"><integer></a> maps to <code>ru_inblock</code> which is the number of times the
file system had to perform input.</li>
<li><code>fsWrite</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type" class="type"><integer></a> maps to <code>ru_oublock</code> which is the number of times the
file system had to perform output.</li>
<li><code>ipcSent</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type" class="type"><integer></a> maps to <code>ru_msgsnd</code> but is not supported by any
platform.</li>
<li><code>ipcReceived</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type" class="type"><integer></a> maps to <code>ru_msgrcv</code> but is not supported by any
platform.</li>
<li><code>signalsCount</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type" class="type"><integer></a> maps to <code>ru_nsignals</code> but is not supported by any
platform.</li>
<li><code>voluntaryContextSwitches</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type" class="type"><integer></a> maps to <code>ru_nvcsw</code> which is the
number of times a CPU context switch resulted due to a process voluntarily
giving up the processor before its time slice was completed (usually to
await availability of a resource). This field is not supported on Windows.</li>
<li><code>involuntaryContextSwitches</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type" class="type"><integer></a> maps to <code>ru_nivcsw</code> which is the
number of times a CPU context switch resulted due to a higher priority
process becoming runnable or because the current process exceeded its
time slice. This field is not supported on Windows.</li>
</ul>
</li>
</ul>
<pre class="with-50-chars"><input class="js-flavor-toggle" type="checkbox" checked aria-label="Show modern ES modules syntax"><code class="language-js mjs"><span class="hljs-keyword">import</span> { resourceUsage } <span class="hljs-keyword">from</span> <span class="hljs-string">'node:process'</span>;
<span class="hljs-variable language_">console</span>.<span class="hljs-title function_">log</span>(<span class="hljs-title function_">resourceUsage</span>());
<span class="hljs-comment">/*
Will output:
{
userCPUTime: 82872,
systemCPUTime: 4143,
maxRSS: 33164,
sharedMemorySize: 0,
unsharedDataSize: 0,
unsharedStackSize: 0,
minorPageFault: 2469,
majorPageFault: 0,
swappedOut: 0,
fsRead: 0,
fsWrite: 8,
ipcSent: 0,
ipcReceived: 0,
signalsCount: 0,
voluntaryContextSwitches: 79,
involuntaryContextSwitches: 1
}
*/</span></code><code class="language-js cjs"><span class="hljs-keyword">const</span> { resourceUsage } = <span class="hljs-built_in">require</span>(<span class="hljs-string">'node:process'</span>);
<span class="hljs-variable language_">console</span>.<span class="hljs-title function_">log</span>(<span class="hljs-title function_">resourceUsage</span>());
<span class="hljs-comment">/*
Will output:
{
userCPUTime: 82872,
systemCPUTime: 4143,
maxRSS: 33164,
sharedMemorySize: 0,
unsharedDataSize: 0,
unsharedStackSize: 0,
minorPageFault: 2469,
majorPageFault: 0,
swappedOut: 0,
fsRead: 0,
fsWrite: 8,
ipcSent: 0,
ipcReceived: 0,
signalsCount: 0,
voluntaryContextSwitches: 79,
involuntaryContextSwitches: 1
}
*/</span></code><button class="copy-button">copy</button></pre>
</section><section><h3><code>process.send(message[, sendHandle[, options]][, callback])</code><span><a class="mark" href="#processsendmessage-sendhandle-options-callback" id="processsendmessage-sendhandle-options-callback">#</a></span><a aria-hidden="true" class="legacy" id="process_process_send_message_sendhandle_options_callback"></a></h3>
<div class="api_metadata">
<span>Added in: v0.5.9</span>
</div>
<ul>
<li><code>message</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object" class="type"><Object></a></li>
<li><code>sendHandle</code> <a href="net.html#class-netserver" class="type"><net.Server></a> | <a href="net.html#class-netsocket" class="type"><net.Socket></a></li>
<li><code>options</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object" class="type"><Object></a> used to parameterize the sending of certain types of
handles.<code>options</code> supports the following properties:
<ul>
<li><code>keepOpen</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Boolean_type" class="type"><boolean></a> A value that can be used when passing instances of
<code>net.Socket</code>. When <code>true</code>, the socket is kept open in the sending process.
<strong>Default:</strong> <code>false</code>.</li>
</ul>
</li>
<li><code>callback</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function" class="type"><Function></a></li>
<li>Returns: <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Boolean_type" class="type"><boolean></a></li>
</ul>
<p>If Node.js is spawned with an IPC channel, the <code>process.send()</code> method can be
used to send messages to the parent process. Messages will be received as a
<a href="child_process.html#event-message"><code>'message'</code></a> event on the parent's <a href="child_process.html#class-childprocess"><code>ChildProcess</code></a> object.</p>
<p>If Node.js was not spawned with an IPC channel, <code>process.send</code> will be
<code>undefined</code>.</p>
<p>The message goes through serialization and parsing. The resulting message might
not be the same as what is originally sent.</p>
</section><section><h3><code>process.setegid(id)</code><span><a class="mark" href="#processsetegidid" id="processsetegidid">#</a></span><a aria-hidden="true" class="legacy" id="process_process_setegid_id"></a></h3>
<div class="api_metadata">
<span>Added in: v2.0.0</span>
</div>
<ul>
<li><code>id</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type"><string></a> | <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type" class="type"><number></a> A group name or ID</li>
</ul>
<p>The <code>process.setegid()</code> method sets the effective group identity of the process.
(See <a href="http://man7.org/linux/man-pages/man2/setegid.2.html"><code>setegid(2)</code></a>.) The <code>id</code> can be passed as either a numeric ID or a group
name string. If a group name is specified, this method blocks while resolving
the associated a numeric ID.</p>
<pre class="with-40-chars"><input class="js-flavor-toggle" type="checkbox" checked aria-label="Show modern ES modules syntax"><code class="language-js mjs"><span class="hljs-keyword">import</span> process <span class="hljs-keyword">from</span> <span class="hljs-string">'node:process'</span>;
<span class="hljs-keyword">if</span> (process.<span class="hljs-property">getegid</span> && process.<span class="hljs-property">setegid</span>) {
<span class="hljs-variable language_">console</span>.<span class="hljs-title function_">log</span>(<span class="hljs-string">`Current gid: <span class="hljs-subst">${process.getegid()}</span>`</span>);
<span class="hljs-keyword">try</span> {
process.<span class="hljs-title function_">setegid</span>(<span class="hljs-number">501</span>);
<span class="hljs-variable language_">console</span>.<span class="hljs-title function_">log</span>(<span class="hljs-string">`New gid: <span class="hljs-subst">${process.getegid()}</span>`</span>);
} <span class="hljs-keyword">catch</span> (err) {
<span class="hljs-variable language_">console</span>.<span class="hljs-title function_">error</span>(<span class="hljs-string">`Failed to set gid: <span class="hljs-subst">${err}</span>`</span>);
}
}</code><code class="language-js cjs"><span class="hljs-keyword">const</span> process = <span class="hljs-built_in">require</span>(<span class="hljs-string">'node:process'</span>);
<span class="hljs-keyword">if</span> (process.<span class="hljs-property">getegid</span> && process.<span class="hljs-property">setegid</span>) {
<span class="hljs-variable language_">console</span>.<span class="hljs-title function_">log</span>(<span class="hljs-string">`Current gid: <span class="hljs-subst">${process.getegid()}</span>`</span>);
<span class="hljs-keyword">try</span> {
process.<span class="hljs-title function_">setegid</span>(<span class="hljs-number">501</span>);
<span class="hljs-variable language_">console</span>.<span class="hljs-title function_">log</span>(<span class="hljs-string">`New gid: <span class="hljs-subst">${process.getegid()}</span>`</span>);
} <span class="hljs-keyword">catch</span> (err) {
<span class="hljs-variable language_">console</span>.<span class="hljs-title function_">error</span>(<span class="hljs-string">`Failed to set gid: <span class="hljs-subst">${err}</span>`</span>);
}
}</code><button class="copy-button">copy</button></pre>
<p>This function is only available on POSIX platforms (i.e. not Windows or
Android).
This feature is not available in <a href="worker_threads.html#class-worker"><code>Worker</code></a> threads.</p>
</section><section><h3><code>process.seteuid(id)</code><span><a class="mark" href="#processseteuidid" id="processseteuidid">#</a></span><a aria-hidden="true" class="legacy" id="process_process_seteuid_id"></a></h3>
<div class="api_metadata">
<span>Added in: v2.0.0</span>
</div>
<ul>
<li><code>id</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type"><string></a> | <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type" class="type"><number></a> A user name or ID</li>
</ul>
<p>The <code>process.seteuid()</code> method sets the effective user identity of the process.
(See <a href="http://man7.org/linux/man-pages/man2/seteuid.2.html"><code>seteuid(2)</code></a>.) The <code>id</code> can be passed as either a numeric ID or a username
string. If a username is specified, the method blocks while resolving the
associated numeric ID.</p>
<pre class="with-40-chars"><input class="js-flavor-toggle" type="checkbox" checked aria-label="Show modern ES modules syntax"><code class="language-js mjs"><span class="hljs-keyword">import</span> process <span class="hljs-keyword">from</span> <span class="hljs-string">'node:process'</span>;
<span class="hljs-keyword">if</span> (process.<span class="hljs-property">geteuid</span> && process.<span class="hljs-property">seteuid</span>) {
<span class="hljs-variable language_">console</span>.<span class="hljs-title function_">log</span>(<span class="hljs-string">`Current uid: <span class="hljs-subst">${process.geteuid()}</span>`</span>);
<span class="hljs-keyword">try</span> {
process.<span class="hljs-title function_">seteuid</span>(<span class="hljs-number">501</span>);
<span class="hljs-variable language_">console</span>.<span class="hljs-title function_">log</span>(<span class="hljs-string">`New uid: <span class="hljs-subst">${process.geteuid()}</span>`</span>);
} <span class="hljs-keyword">catch</span> (err) {
<span class="hljs-variable language_">console</span>.<span class="hljs-title function_">error</span>(<span class="hljs-string">`Failed to set uid: <span class="hljs-subst">${err}</span>`</span>);
}
}</code><code class="language-js cjs"><span class="hljs-keyword">const</span> process = <span class="hljs-built_in">require</span>(<span class="hljs-string">'node:process'</span>);
<span class="hljs-keyword">if</span> (process.<span class="hljs-property">geteuid</span> && process.<span class="hljs-property">seteuid</span>) {
<span class="hljs-variable language_">console</span>.<span class="hljs-title function_">log</span>(<span class="hljs-string">`Current uid: <span class="hljs-subst">${process.geteuid()}</span>`</span>);
<span class="hljs-keyword">try</span> {
process.<span class="hljs-title function_">seteuid</span>(<span class="hljs-number">501</span>);
<span class="hljs-variable language_">console</span>.<span class="hljs-title function_">log</span>(<span class="hljs-string">`New uid: <span class="hljs-subst">${process.geteuid()}</span>`</span>);
} <span class="hljs-keyword">catch</span> (err) {
<span class="hljs-variable language_">console</span>.<span class="hljs-title function_">error</span>(<span class="hljs-string">`Failed to set uid: <span class="hljs-subst">${err}</span>`</span>);
}
}</code><button class="copy-button">copy</button></pre>
<p>This function is only available on POSIX platforms (i.e. not Windows or
Android).
This feature is not available in <a href="worker_threads.html#class-worker"><code>Worker</code></a> threads.</p>
</section><section><h3><code>process.setgid(id)</code><span><a class="mark" href="#processsetgidid" id="processsetgidid">#</a></span><a aria-hidden="true" class="legacy" id="process_process_setgid_id"></a></h3>
<div class="api_metadata">
<span>Added in: v0.1.31</span>
</div>
<ul>
<li><code>id</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type"><string></a> | <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type" class="type"><number></a> The group name or ID</li>
</ul>
<p>The <code>process.setgid()</code> method sets the group identity of the process. (See
<a href="http://man7.org/linux/man-pages/man2/setgid.2.html"><code>setgid(2)</code></a>.) The <code>id</code> can be passed as either a numeric ID or a group name
string. If a group name is specified, this method blocks while resolving the
associated numeric ID.</p>
<pre class="with-40-chars"><input class="js-flavor-toggle" type="checkbox" checked aria-label="Show modern ES modules syntax"><code class="language-js mjs"><span class="hljs-keyword">import</span> process <span class="hljs-keyword">from</span> <span class="hljs-string">'node:process'</span>;
<span class="hljs-keyword">if</span> (process.<span class="hljs-property">getgid</span> && process.<span class="hljs-property">setgid</span>) {
<span class="hljs-variable language_">console</span>.<span class="hljs-title function_">log</span>(<span class="hljs-string">`Current gid: <span class="hljs-subst">${process.getgid()}</span>`</span>);
<span class="hljs-keyword">try</span> {
process.<span class="hljs-title function_">setgid</span>(<span class="hljs-number">501</span>);
<span class="hljs-variable language_">console</span>.<span class="hljs-title function_">log</span>(<span class="hljs-string">`New gid: <span class="hljs-subst">${process.getgid()}</span>`</span>);
} <span class="hljs-keyword">catch</span> (err) {
<span class="hljs-variable language_">console</span>.<span class="hljs-title function_">error</span>(<span class="hljs-string">`Failed to set gid: <span class="hljs-subst">${err}</span>`</span>);
}
}</code><code class="language-js cjs"><span class="hljs-keyword">const</span> process = <span class="hljs-built_in">require</span>(<span class="hljs-string">'node:process'</span>);
<span class="hljs-keyword">if</span> (process.<span class="hljs-property">getgid</span> && process.<span class="hljs-property">setgid</span>) {
<span class="hljs-variable language_">console</span>.<span class="hljs-title function_">log</span>(<span class="hljs-string">`Current gid: <span class="hljs-subst">${process.getgid()}</span>`</span>);
<span class="hljs-keyword">try</span> {
process.<span class="hljs-title function_">setgid</span>(<span class="hljs-number">501</span>);
<span class="hljs-variable language_">console</span>.<span class="hljs-title function_">log</span>(<span class="hljs-string">`New gid: <span class="hljs-subst">${process.getgid()}</span>`</span>);
} <span class="hljs-keyword">catch</span> (err) {
<span class="hljs-variable language_">console</span>.<span class="hljs-title function_">error</span>(<span class="hljs-string">`Failed to set gid: <span class="hljs-subst">${err}</span>`</span>);
}
}</code><button class="copy-button">copy</button></pre>
<p>This function is only available on POSIX platforms (i.e. not Windows or
Android).
This feature is not available in <a href="worker_threads.html#class-worker"><code>Worker</code></a> threads.</p>
</section><section><h3><code>process.setgroups(groups)</code><span><a class="mark" href="#processsetgroupsgroups" id="processsetgroupsgroups">#</a></span><a aria-hidden="true" class="legacy" id="process_process_setgroups_groups"></a></h3>
<div class="api_metadata">
<span>Added in: v0.9.4</span>
</div>
<ul>
<li><code>groups</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type" class="type"><integer[]></a></li>
</ul>
<p>The <code>process.setgroups()</code> method sets the supplementary group IDs for the
Node.js process. This is a privileged operation that requires the Node.js
process to have <code>root</code> or the <code>CAP_SETGID</code> capability.</p>
<p>The <code>groups</code> array can contain numeric group IDs, group names, or both.</p>
<pre class="with-40-chars"><input class="js-flavor-toggle" type="checkbox" checked aria-label="Show modern ES modules syntax"><code class="language-js mjs"><span class="hljs-keyword">import</span> process <span class="hljs-keyword">from</span> <span class="hljs-string">'node:process'</span>;
<span class="hljs-keyword">if</span> (process.<span class="hljs-property">getgroups</span> && process.<span class="hljs-property">setgroups</span>) {
<span class="hljs-keyword">try</span> {
process.<span class="hljs-title function_">setgroups</span>([<span class="hljs-number">501</span>]);
<span class="hljs-variable language_">console</span>.<span class="hljs-title function_">log</span>(process.<span class="hljs-title function_">getgroups</span>()); <span class="hljs-comment">// new groups</span>
} <span class="hljs-keyword">catch</span> (err) {
<span class="hljs-variable language_">console</span>.<span class="hljs-title function_">error</span>(<span class="hljs-string">`Failed to set groups: <span class="hljs-subst">${err}</span>`</span>);
}
}</code><code class="language-js cjs"><span class="hljs-keyword">const</span> process = <span class="hljs-built_in">require</span>(<span class="hljs-string">'node:process'</span>);
<span class="hljs-keyword">if</span> (process.<span class="hljs-property">getgroups</span> && process.<span class="hljs-property">setgroups</span>) {
<span class="hljs-keyword">try</span> {
process.<span class="hljs-title function_">setgroups</span>([<span class="hljs-number">501</span>]);
<span class="hljs-variable language_">console</span>.<span class="hljs-title function_">log</span>(process.<span class="hljs-title function_">getgroups</span>()); <span class="hljs-comment">// new groups</span>
} <span class="hljs-keyword">catch</span> (err) {
<span class="hljs-variable language_">console</span>.<span class="hljs-title function_">error</span>(<span class="hljs-string">`Failed to set groups: <span class="hljs-subst">${err}</span>`</span>);
}
}</code><button class="copy-button">copy</button></pre>
<p>This function is only available on POSIX platforms (i.e. not Windows or
Android).
This feature is not available in <a href="worker_threads.html#class-worker"><code>Worker</code></a> threads.</p>
</section><section><h3><code>process.setuid(id)</code><span><a class="mark" href="#processsetuidid" id="processsetuidid">#</a></span><a aria-hidden="true" class="legacy" id="process_process_setuid_id"></a></h3>
<div class="api_metadata">
<span>Added in: v0.1.28</span>
</div>
<ul>
<li><code>id</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type" class="type"><integer></a> | <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type"><string></a></li>
</ul>
<p>The <code>process.setuid(id)</code> method sets the user identity of the process. (See
<a href="http://man7.org/linux/man-pages/man2/setuid.2.html"><code>setuid(2)</code></a>.) The <code>id</code> can be passed as either a numeric ID or a username string.
If a username is specified, the method blocks while resolving the associated
numeric ID.</p>
<pre class="with-40-chars"><input class="js-flavor-toggle" type="checkbox" checked aria-label="Show modern ES modules syntax"><code class="language-js mjs"><span class="hljs-keyword">import</span> process <span class="hljs-keyword">from</span> <span class="hljs-string">'node:process'</span>;
<span class="hljs-keyword">if</span> (process.<span class="hljs-property">getuid</span> && process.<span class="hljs-property">setuid</span>) {
<span class="hljs-variable language_">console</span>.<span class="hljs-title function_">log</span>(<span class="hljs-string">`Current uid: <span class="hljs-subst">${process.getuid()}</span>`</span>);
<span class="hljs-keyword">try</span> {
process.<span class="hljs-title function_">setuid</span>(<span class="hljs-number">501</span>);
<span class="hljs-variable language_">console</span>.<span class="hljs-title function_">log</span>(<span class="hljs-string">`New uid: <span class="hljs-subst">${process.getuid()}</span>`</span>);
} <span class="hljs-keyword">catch</span> (err) {
<span class="hljs-variable language_">console</span>.<span class="hljs-title function_">error</span>(<span class="hljs-string">`Failed to set uid: <span class="hljs-subst">${err}</span>`</span>);
}
}</code><code class="language-js cjs"><span class="hljs-keyword">const</span> process = <span class="hljs-built_in">require</span>(<span class="hljs-string">'node:process'</span>);
<span class="hljs-keyword">if</span> (process.<span class="hljs-property">getuid</span> && process.<span class="hljs-property">setuid</span>) {
<span class="hljs-variable language_">console</span>.<span class="hljs-title function_">log</span>(<span class="hljs-string">`Current uid: <span class="hljs-subst">${process.getuid()}</span>`</span>);
<span class="hljs-keyword">try</span> {
process.<span class="hljs-title function_">setuid</span>(<span class="hljs-number">501</span>);
<span class="hljs-variable language_">console</span>.<span class="hljs-title function_">log</span>(<span class="hljs-string">`New uid: <span class="hljs-subst">${process.getuid()}</span>`</span>);
} <span class="hljs-keyword">catch</span> (err) {
<span class="hljs-variable language_">console</span>.<span class="hljs-title function_">error</span>(<span class="hljs-string">`Failed to set uid: <span class="hljs-subst">${err}</span>`</span>);
}
}</code><button class="copy-button">copy</button></pre>
<p>This function is only available on POSIX platforms (i.e. not Windows or
Android).
This feature is not available in <a href="worker_threads.html#class-worker"><code>Worker</code></a> threads.</p>
</section><section><h3><code>process.setSourceMapsEnabled(val)</code><span><a class="mark" href="#processsetsourcemapsenabledval" id="processsetsourcemapsenabledval">#</a></span><a aria-hidden="true" class="legacy" id="process_process_setsourcemapsenabled_val"></a></h3>
<div class="api_metadata">
<span>Added in: v16.6.0, v14.18.0</span>
</div>
<p></p><div class="api_stability api_stability_1"><a href="documentation.html#stability-index">Stability: 1</a> - Experimental: Use <a href="module.html#modulesetsourcemapssupportenabled-options"><code>module.setSourceMapsSupport()</code></a> instead.</div><p></p>
<ul>
<li><code>val</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Boolean_type" class="type"><boolean></a></li>
</ul>
<p>This function enables or disables the <a href="https://sourcemaps.info/spec.html">Source Map v3</a> support for
stack traces.</p>
<p>It provides same features as launching Node.js process with commandline options
<code>--enable-source-maps</code>.</p>
<p>Only source maps in JavaScript files that are loaded after source maps has been
enabled will be parsed and loaded.</p>
<p>This implies calling <code>module.setSourceMapsSupport()</code> with an option
<code>{ nodeModules: true, generatedCode: true }</code>.</p>
</section><section><h3><code>process.setUncaughtExceptionCaptureCallback(fn)</code><span><a class="mark" href="#processsetuncaughtexceptioncapturecallbackfn" id="processsetuncaughtexceptioncapturecallbackfn">#</a></span><a aria-hidden="true" class="legacy" id="process_process_setuncaughtexceptioncapturecallback_fn"></a></h3>
<div class="api_metadata">
<span>Added in: v9.3.0</span>
</div>
<ul>
<li><code>fn</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function" class="type"><Function></a> | <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Null_type" class="type"><null></a></li>
</ul>
<p>The <code>process.setUncaughtExceptionCaptureCallback()</code> function sets a function
that will be invoked when an uncaught exception occurs, which will receive the
exception value itself as its first argument.</p>
<p>If such a function is set, the <a href="#event-uncaughtexception"><code>'uncaughtException'</code></a> event will
not be emitted. If <code>--abort-on-uncaught-exception</code> was passed from the
command line or set through <a href="v8.html#v8setflagsfromstringflags"><code>v8.setFlagsFromString()</code></a>, the process will
not abort. Actions configured to take place on exceptions such as report
generations will be affected too</p>
<p>To unset the capture function,
<code>process.setUncaughtExceptionCaptureCallback(null)</code> may be used. Calling this
method with a non-<code>null</code> argument while another capture function is set will
throw an error.</p>
<p>Using this function is mutually exclusive with using the deprecated
<a href="domain.html"><code>domain</code></a> built-in module.</p>
</section><section><h3><code>process.sourceMapsEnabled</code><span><a class="mark" href="#processsourcemapsenabled" id="processsourcemapsenabled">#</a></span><a aria-hidden="true" class="legacy" id="process_process_sourcemapsenabled"></a></h3>
<div class="api_metadata">
<span>Added in: v20.7.0, v18.19.0</span>
</div>
<p></p><div class="api_stability api_stability_1"><a href="documentation.html#stability-index">Stability: 1</a> - Experimental: Use <a href="module.html#modulegetsourcemapssupport"><code>module.getSourceMapsSupport()</code></a> instead.</div><p></p>
<ul>
<li><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Boolean_type" class="type"><boolean></a></li>
</ul>
<p>The <code>process.sourceMapsEnabled</code> property returns whether the
<a href="https://sourcemaps.info/spec.html">Source Map v3</a> support for stack traces is enabled.</p>
</section><section><h3><code>process.stderr</code><span><a class="mark" href="#processstderr" id="processstderr">#</a></span><a aria-hidden="true" class="legacy" id="process_process_stderr"></a></h3>
<ul>
<li><a href="stream.html#stream" class="type"><Stream></a></li>
</ul>
<p>The <code>process.stderr</code> property returns a stream connected to
<code>stderr</code> (fd <code>2</code>). It is a <a href="net.html#class-netsocket"><code>net.Socket</code></a> (which is a <a href="stream.html#duplex-and-transform-streams">Duplex</a>
stream) unless fd <code>2</code> refers to a file, in which case it is
a <a href="stream.html#writable-streams">Writable</a> stream.</p>
<p><code>process.stderr</code> differs from other Node.js streams in important ways. See
<a href="#a-note-on-process-io">note on process I/O</a> for more information.</p>
<h4><code>process.stderr.fd</code><span><a class="mark" href="#processstderrfd" id="processstderrfd">#</a></span><a aria-hidden="true" class="legacy" id="process_process_stderr_fd"></a></h4>
<ul>
<li><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type" class="type"><number></a></li>
</ul>
<p>This property refers to the value of underlying file descriptor of
<code>process.stderr</code>. The value is fixed at <code>2</code>. In <a href="worker_threads.html#class-worker"><code>Worker</code></a> threads,
this field does not exist.</p>
</section><section><h3><code>process.stdin</code><span><a class="mark" href="#processstdin" id="processstdin">#</a></span><a aria-hidden="true" class="legacy" id="process_process_stdin"></a></h3>
<ul>
<li><a href="stream.html#stream" class="type"><Stream></a></li>
</ul>
<p>The <code>process.stdin</code> property returns a stream connected to
<code>stdin</code> (fd <code>0</code>). It is a <a href="net.html#class-netsocket"><code>net.Socket</code></a> (which is a <a href="stream.html#duplex-and-transform-streams">Duplex</a>
stream) unless fd <code>0</code> refers to a file, in which case it is
a <a href="stream.html#readable-streams">Readable</a> stream.</p>
<p>For details of how to read from <code>stdin</code> see <a href="stream.html#readablereadsize"><code>readable.read()</code></a>.</p>
<p>As a <a href="stream.html#duplex-and-transform-streams">Duplex</a> stream, <code>process.stdin</code> can also be used in "old" mode that
is compatible with scripts written for Node.js prior to v0.10.
For more information see <a href="stream.html#compatibility-with-older-nodejs-versions">Stream compatibility</a>.</p>
<p>In "old" streams mode the <code>stdin</code> stream is paused by default, so one
must call <code>process.stdin.resume()</code> to read from it. Note also that calling
<code>process.stdin.resume()</code> itself would switch stream to "old" mode.</p>
<h4><code>process.stdin.fd</code><span><a class="mark" href="#processstdinfd" id="processstdinfd">#</a></span><a aria-hidden="true" class="legacy" id="process_process_stdin_fd"></a></h4>
<ul>
<li><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type" class="type"><number></a></li>
</ul>
<p>This property refers to the value of underlying file descriptor of
<code>process.stdin</code>. The value is fixed at <code>0</code>. In <a href="worker_threads.html#class-worker"><code>Worker</code></a> threads,
this field does not exist.</p>
</section><section><h3><code>process.stdout</code><span><a class="mark" href="#processstdout" id="processstdout">#</a></span><a aria-hidden="true" class="legacy" id="process_process_stdout"></a></h3>
<ul>
<li><a href="stream.html#stream" class="type"><Stream></a></li>
</ul>
<p>The <code>process.stdout</code> property returns a stream connected to
<code>stdout</code> (fd <code>1</code>). It is a <a href="net.html#class-netsocket"><code>net.Socket</code></a> (which is a <a href="stream.html#duplex-and-transform-streams">Duplex</a>
stream) unless fd <code>1</code> refers to a file, in which case it is
a <a href="stream.html#writable-streams">Writable</a> stream.</p>
<p>For example, to copy <code>process.stdin</code> to <code>process.stdout</code>:</p>
<pre class="with-50-chars"><input class="js-flavor-toggle" type="checkbox" checked aria-label="Show modern ES modules syntax"><code class="language-js mjs"><span class="hljs-keyword">import</span> { stdin, stdout } <span class="hljs-keyword">from</span> <span class="hljs-string">'node:process'</span>;
stdin.<span class="hljs-title function_">pipe</span>(stdout);</code><code class="language-js cjs"><span class="hljs-keyword">const</span> { stdin, stdout } = <span class="hljs-built_in">require</span>(<span class="hljs-string">'node:process'</span>);
stdin.<span class="hljs-title function_">pipe</span>(stdout);</code><button class="copy-button">copy</button></pre>
<p><code>process.stdout</code> differs from other Node.js streams in important ways. See
<a href="#a-note-on-process-io">note on process I/O</a> for more information.</p>
<h4><code>process.stdout.fd</code><span><a class="mark" href="#processstdoutfd" id="processstdoutfd">#</a></span><a aria-hidden="true" class="legacy" id="process_process_stdout_fd"></a></h4>
<ul>
<li><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type" class="type"><number></a></li>
</ul>
<p>This property refers to the value of underlying file descriptor of
<code>process.stdout</code>. The value is fixed at <code>1</code>. In <a href="worker_threads.html#class-worker"><code>Worker</code></a> threads,
this field does not exist.</p>
<h4>A note on process I/O<span><a class="mark" href="#a-note-on-process-io" id="a-note-on-process-io">#</a></span><a aria-hidden="true" class="legacy" id="process_a_note_on_process_i_o"></a></h4>
<p><code>process.stdout</code> and <code>process.stderr</code> differ from other Node.js streams in
important ways:</p>
<ol>
<li>They are used internally by <a href="console.html#consolelogdata-args"><code>console.log()</code></a> and <a href="console.html#consoleerrordata-args"><code>console.error()</code></a>,
respectively.</li>
<li>Writes may be synchronous depending on what the stream is connected to
and whether the system is Windows or POSIX:
<ul>
<li>Files: <em>synchronous</em> on Windows and POSIX</li>
<li>TTYs (Terminals): <em>asynchronous</em> on Windows, <em>synchronous</em> on POSIX</li>
<li>Pipes (and sockets): <em>synchronous</em> on Windows, <em>asynchronous</em> on POSIX</li>
</ul>
</li>
</ol>
<p>These behaviors are partly for historical reasons, as changing them would
create backward incompatibility, but they are also expected by some users.</p>
<p>Synchronous writes avoid problems such as output written with <code>console.log()</code> or
<code>console.error()</code> being unexpectedly interleaved, or not written at all if
<code>process.exit()</code> is called before an asynchronous write completes. See
<a href="#processexitcode"><code>process.exit()</code></a> for more information.</p>
<p><em><strong>Warning</strong></em>: Synchronous writes block the event loop until the write has
completed. This can be near instantaneous in the case of output to a file, but
under high system load, pipes that are not being read at the receiving end, or
with slow terminals or file systems, it's possible for the event loop to be
blocked often enough and long enough to have severe negative performance
impacts. This may not be a problem when writing to an interactive terminal
session, but consider this particularly careful when doing production logging to
the process output streams.</p>
<p>To check if a stream is connected to a <a href="tty.html#tty">TTY</a> context, check the <code>isTTY</code>
property.</p>
<p>For instance:</p>
<pre><code class="language-console"><span class="hljs-meta prompt_">$ </span><span class="language-bash">node -p <span class="hljs-string">"Boolean(process.stdin.isTTY)"</span></span>
true
<span class="hljs-meta prompt_">$ </span><span class="language-bash"><span class="hljs-built_in">echo</span> <span class="hljs-string">"foo"</span> | node -p <span class="hljs-string">"Boolean(process.stdin.isTTY)"</span></span>
false
<span class="hljs-meta prompt_">$ </span><span class="language-bash">node -p <span class="hljs-string">"Boolean(process.stdout.isTTY)"</span></span>
true
<span class="hljs-meta prompt_">$ </span><span class="language-bash">node -p <span class="hljs-string">"Boolean(process.stdout.isTTY)"</span> | <span class="hljs-built_in">cat</span></span>
false</code> <button class="copy-button">copy</button></pre>
<p>See the <a href="tty.html#tty">TTY</a> documentation for more information.</p>
</section><section><h3><code>process.throwDeprecation</code><span><a class="mark" href="#processthrowdeprecation" id="processthrowdeprecation">#</a></span><a aria-hidden="true" class="legacy" id="process_process_throwdeprecation"></a></h3>
<div class="api_metadata">
<span>Added in: v0.9.12</span>
</div>
<ul>
<li><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Boolean_type" class="type"><boolean></a></li>
</ul>
<p>The initial value of <code>process.throwDeprecation</code> indicates whether the
<code>--throw-deprecation</code> flag is set on the current Node.js process.
<code>process.throwDeprecation</code> is mutable, so whether or not deprecation
warnings result in errors may be altered at runtime. See the
documentation for the <a href="#event-warning"><code>'warning'</code> event</a> and the
<a href="#processemitwarningwarning-type-code-ctor"><code>emitWarning()</code> method</a> for more information.</p>
<pre><code class="language-console"><span class="hljs-meta prompt_">$ </span><span class="language-bash">node --throw-deprecation -p <span class="hljs-string">"process.throwDeprecation"</span></span>
true
<span class="hljs-meta prompt_">$ </span><span class="language-bash">node -p <span class="hljs-string">"process.throwDeprecation"</span></span>
undefined
<span class="hljs-meta prompt_">$ </span><span class="language-bash">node</span>
<span class="hljs-meta prompt_">> </span><span class="language-bash">process.emitWarning(<span class="hljs-string">'test'</span>, <span class="hljs-string">'DeprecationWarning'</span>);</span>
undefined
<span class="hljs-meta prompt_">> </span><span class="language-bash">(node:26598) DeprecationWarning: <span class="hljs-built_in">test</span></span>
<span class="hljs-meta prompt_">> </span><span class="language-bash">process.throwDeprecation = <span class="hljs-literal">true</span>;</span>
true
<span class="hljs-meta prompt_">> </span><span class="language-bash">process.emitWarning(<span class="hljs-string">'test'</span>, <span class="hljs-string">'DeprecationWarning'</span>);</span>
Thrown:
[DeprecationWarning: test] { name: 'DeprecationWarning' }</code> <button class="copy-button">copy</button></pre>
</section><section><h3><code>process.title</code><span><a class="mark" href="#processtitle" id="processtitle">#</a></span><a aria-hidden="true" class="legacy" id="process_process_title"></a></h3>
<div class="api_metadata">
<span>Added in: v0.1.104</span>
</div>
<ul>
<li><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type"><string></a></li>
</ul>
<p>The <code>process.title</code> property returns the current process title (i.e. returns
the current value of <code>ps</code>). Assigning a new value to <code>process.title</code> modifies
the current value of <code>ps</code>.</p>
<p>When a new value is assigned, different platforms will impose different maximum
length restrictions on the title. Usually such restrictions are quite limited.
For instance, on Linux and macOS, <code>process.title</code> is limited to the size of the
binary name plus the length of the command-line arguments because setting the
<code>process.title</code> overwrites the <code>argv</code> memory of the process. Node.js v0.8
allowed for longer process title strings by also overwriting the <code>environ</code>
memory but that was potentially insecure and confusing in some (rather obscure)
cases.</p>
<p>Assigning a value to <code>process.title</code> might not result in an accurate label
within process manager applications such as macOS Activity Monitor or Windows
Services Manager.</p>
</section><section><h3><code>process.traceDeprecation</code><span><a class="mark" href="#processtracedeprecation" id="processtracedeprecation">#</a></span><a aria-hidden="true" class="legacy" id="process_process_tracedeprecation"></a></h3>
<div class="api_metadata">
<span>Added in: v0.8.0</span>
</div>
<ul>
<li><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Boolean_type" class="type"><boolean></a></li>
</ul>
<p>The <code>process.traceDeprecation</code> property indicates whether the
<code>--trace-deprecation</code> flag is set on the current Node.js process. See the
documentation for the <a href="#event-warning"><code>'warning'</code> event</a> and the
<a href="#processemitwarningwarning-type-code-ctor"><code>emitWarning()</code> method</a> for more information about this
flag's behavior.</p>
</section><section><h3><code>process.umask()</code><span><a class="mark" href="#processumask" id="processumask">#</a></span><a aria-hidden="true" class="legacy" id="process_process_umask"></a></h3>
<div class="api_metadata">
<details class="changelog"><summary>History</summary>
<table>
<tbody><tr><th>Version</th><th>Changes</th></tr>
<tr><td>v14.0.0, v12.19.0</td>
<td><p>Calling <code>process.umask()</code> with no arguments is deprecated.</p></td></tr>
<tr><td>v0.1.19</td>
<td><p><span>Added in: v0.1.19</span></p></td></tr>
</tbody></table>
</details>
</div>
<p></p><div class="api_stability api_stability_0"><a href="documentation.html#stability-index">Stability: 0</a> - Deprecated. Calling <code>process.umask()</code> with no argument causes
the process-wide umask to be written twice. This introduces a race condition
between threads, and is a potential security vulnerability. There is no safe,
cross-platform alternative API.</div><p></p>
<p><code>process.umask()</code> returns the Node.js process's file mode creation mask. Child
processes inherit the mask from the parent process.</p>
</section><section><h3><code>process.umask(mask)</code><span><a class="mark" href="#processumaskmask" id="processumaskmask">#</a></span><a aria-hidden="true" class="legacy" id="process_process_umask_mask"></a></h3>
<div class="api_metadata">
<span>Added in: v0.1.19</span>
</div>
<ul>
<li><code>mask</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type"><string></a> | <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type" class="type"><integer></a></li>
</ul>
<p><code>process.umask(mask)</code> sets the Node.js process's file mode creation mask. Child
processes inherit the mask from the parent process. Returns the previous mask.</p>
<pre class="with-42-chars"><input class="js-flavor-toggle" type="checkbox" checked aria-label="Show modern ES modules syntax"><code class="language-js mjs"><span class="hljs-keyword">import</span> { umask } <span class="hljs-keyword">from</span> <span class="hljs-string">'node:process'</span>;
<span class="hljs-keyword">const</span> newmask = <span class="hljs-number">0o022</span>;
<span class="hljs-keyword">const</span> oldmask = <span class="hljs-title function_">umask</span>(newmask);
<span class="hljs-variable language_">console</span>.<span class="hljs-title function_">log</span>(
<span class="hljs-string">`Changed umask from <span class="hljs-subst">${oldmask.toString(<span class="hljs-number">8</span>)}</span> to <span class="hljs-subst">${newmask.toString(<span class="hljs-number">8</span>)}</span>`</span>,
);</code><code class="language-js cjs"><span class="hljs-keyword">const</span> { umask } = <span class="hljs-built_in">require</span>(<span class="hljs-string">'node:process'</span>);
<span class="hljs-keyword">const</span> newmask = <span class="hljs-number">0o022</span>;
<span class="hljs-keyword">const</span> oldmask = <span class="hljs-title function_">umask</span>(newmask);
<span class="hljs-variable language_">console</span>.<span class="hljs-title function_">log</span>(
<span class="hljs-string">`Changed umask from <span class="hljs-subst">${oldmask.toString(<span class="hljs-number">8</span>)}</span> to <span class="hljs-subst">${newmask.toString(<span class="hljs-number">8</span>)}</span>`</span>,
);</code><button class="copy-button">copy</button></pre>
<p>In <a href="worker_threads.html#class-worker"><code>Worker</code></a> threads, <code>process.umask(mask)</code> will throw an exception.</p>
</section><section><h3><code>process.unref(maybeRefable)</code><span><a class="mark" href="#processunrefmayberefable" id="processunrefmayberefable">#</a></span><a aria-hidden="true" class="legacy" id="process_process_unref_mayberefable"></a></h3>
<div class="api_metadata">
<span>Added in: v22.14.0</span>
</div>
<p></p><div class="api_stability api_stability_1"><a href="documentation.html#stability-index">Stability: 1</a> - Experimental</div><p></p>
<ul>
<li><code>maybeUnfefable</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Data_types" class="type"><any></a> An object that may be "unref'd".</li>
</ul>
<p>An object is "unrefable" if it implements the Node.js "Refable protocol".
Specifically, this means that the object implements the <code>Symbol.for('nodejs.ref')</code>
and <code>Symbol.for('nodejs.unref')</code> methods. "Ref'd" objects will keep the Node.js
event loop alive, while "unref'd" objects will not. Historically, this was
implemented by using <code>ref()</code> and <code>unref()</code> methods directly on the objects.
This pattern, however, is being deprecated in favor of the "Refable protocol"
in order to better support Web Platform API types whose APIs cannot be modified
to add <code>ref()</code> and <code>unref()</code> methods but still need to support that behavior.</p>
</section><section><h3><code>process.uptime()</code><span><a class="mark" href="#processuptime" id="processuptime">#</a></span><a aria-hidden="true" class="legacy" id="process_process_uptime"></a></h3>
<div class="api_metadata">
<span>Added in: v0.5.0</span>
</div>
<ul>
<li>Returns: <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type" class="type"><number></a></li>
</ul>
<p>The <code>process.uptime()</code> method returns the number of seconds the current Node.js
process has been running.</p>
<p>The return value includes fractions of a second. Use <code>Math.floor()</code> to get whole
seconds.</p>
</section><section><h3><code>process.version</code><span><a class="mark" href="#processversion" id="processversion">#</a></span><a aria-hidden="true" class="legacy" id="process_process_version"></a></h3>
<div class="api_metadata">
<span>Added in: v0.1.3</span>
</div>
<ul>
<li><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type"><string></a></li>
</ul>
<p>The <code>process.version</code> property contains the Node.js version string.</p>
<pre class="with-44-chars"><input class="js-flavor-toggle" type="checkbox" checked aria-label="Show modern ES modules syntax"><code class="language-js mjs"><span class="hljs-keyword">import</span> { version } <span class="hljs-keyword">from</span> <span class="hljs-string">'node:process'</span>;
<span class="hljs-variable language_">console</span>.<span class="hljs-title function_">log</span>(<span class="hljs-string">`Version: <span class="hljs-subst">${version}</span>`</span>);
<span class="hljs-comment">// Version: v14.8.0</span></code><code class="language-js cjs"><span class="hljs-keyword">const</span> { version } = <span class="hljs-built_in">require</span>(<span class="hljs-string">'node:process'</span>);
<span class="hljs-variable language_">console</span>.<span class="hljs-title function_">log</span>(<span class="hljs-string">`Version: <span class="hljs-subst">${version}</span>`</span>);
<span class="hljs-comment">// Version: v14.8.0</span></code><button class="copy-button">copy</button></pre>
<p>To get the version string without the prepended <em>v</em>, use
<code>process.versions.node</code>.</p>
</section><section><h3><code>process.versions</code><span><a class="mark" href="#processversions" id="processversions">#</a></span><a aria-hidden="true" class="legacy" id="process_process_versions"></a></h3>
<div class="api_metadata">
<details class="changelog"><summary>History</summary>
<table>
<tbody><tr><th>Version</th><th>Changes</th></tr>
<tr><td>v9.0.0</td>
<td><p>The <code>v8</code> property now includes a Node.js specific suffix.</p></td></tr>
<tr><td>v4.2.0</td>
<td><p>The <code>icu</code> property is now supported.</p></td></tr>
<tr><td>v0.2.0</td>
<td><p><span>Added in: v0.2.0</span></p></td></tr>
</tbody></table>
</details>
</div>
<ul>
<li><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object" class="type"><Object></a></li>
</ul>
<p>The <code>process.versions</code> property returns an object listing the version strings of
Node.js and its dependencies. <code>process.versions.modules</code> indicates the current
ABI version, which is increased whenever a C++ API changes. Node.js will refuse
to load modules that were compiled against a different module ABI version.</p>
<pre class="with-45-chars"><input class="js-flavor-toggle" type="checkbox" checked aria-label="Show modern ES modules syntax"><code class="language-js mjs"><span class="hljs-keyword">import</span> { versions } <span class="hljs-keyword">from</span> <span class="hljs-string">'node:process'</span>;
<span class="hljs-variable language_">console</span>.<span class="hljs-title function_">log</span>(versions);</code><code class="language-js cjs"><span class="hljs-keyword">const</span> { versions } = <span class="hljs-built_in">require</span>(<span class="hljs-string">'node:process'</span>);
<span class="hljs-variable language_">console</span>.<span class="hljs-title function_">log</span>(versions);</code><button class="copy-button">copy</button></pre>
<p>Will generate an object similar to:</p>
<pre><code class="language-console">{ node: '23.0.0',
acorn: '8.11.3',
ada: '2.7.8',
ares: '1.28.1',
base64: '0.5.2',
brotli: '1.1.0',
cjs_module_lexer: '1.2.2',
cldr: '45.0',
icu: '75.1',
llhttp: '9.2.1',
modules: '127',
napi: '9',
nghttp2: '1.61.0',
nghttp3: '0.7.0',
ngtcp2: '1.3.0',
openssl: '3.0.13+quic',
simdjson: '3.8.0',
simdutf: '5.2.4',
sqlite: '3.46.0',
tz: '2024a',
undici: '6.13.0',
unicode: '15.1',
uv: '1.48.0',
uvwasi: '0.0.20',
v8: '12.4.254.14-node.11',
zlib: '1.3.0.1-motley-7d77fb7' }</code> <button class="copy-button">copy</button></pre>
</section><section><h3>Exit codes<span><a class="mark" href="#exit-codes" id="exit-codes">#</a></span><a aria-hidden="true" class="legacy" id="process_exit_codes"></a></h3>
<p>Node.js will normally exit with a <code>0</code> status code when no more async
operations are pending. The following status codes are used in other
cases:</p>
<ul>
<li><code>1</code> <strong>Uncaught Fatal Exception</strong>: There was an uncaught exception,
and it was not handled by a domain or an <a href="#event-uncaughtexception"><code>'uncaughtException'</code></a> event
handler.</li>
<li><code>2</code>: Unused (reserved by Bash for builtin misuse)</li>
<li><code>3</code> <strong>Internal JavaScript Parse Error</strong>: The JavaScript source code
internal in the Node.js bootstrapping process caused a parse error. This
is extremely rare, and generally can only happen during development
of Node.js itself.</li>
<li><code>4</code> <strong>Internal JavaScript Evaluation Failure</strong>: The JavaScript
source code internal in the Node.js bootstrapping process failed to
return a function value when evaluated. This is extremely rare, and
generally can only happen during development of Node.js itself.</li>
<li><code>5</code> <strong>Fatal Error</strong>: There was a fatal unrecoverable error in V8.
Typically a message will be printed to stderr with the prefix <code>FATAL ERROR</code>.</li>
<li><code>6</code> <strong>Non-function Internal Exception Handler</strong>: There was an
uncaught exception, but the internal fatal exception handler
function was somehow set to a non-function, and could not be called.</li>
<li><code>7</code> <strong>Internal Exception Handler Run-Time Failure</strong>: There was an
uncaught exception, and the internal fatal exception handler
function itself threw an error while attempting to handle it. This
can happen, for example, if an <a href="#event-uncaughtexception"><code>'uncaughtException'</code></a> or
<code>domain.on('error')</code> handler throws an error.</li>
<li><code>8</code>: Unused. In previous versions of Node.js, exit code 8 sometimes
indicated an uncaught exception.</li>
<li><code>9</code> <strong>Invalid Argument</strong>: Either an unknown option was specified,
or an option requiring a value was provided without a value.</li>
<li><code>10</code> <strong>Internal JavaScript Run-Time Failure</strong>: The JavaScript
source code internal in the Node.js bootstrapping process threw an error
when the bootstrapping function was called. This is extremely rare,
and generally can only happen during development of Node.js itself.</li>
<li><code>12</code> <strong>Invalid Debug Argument</strong>: The <code>--inspect</code> and/or <code>--inspect-brk</code>
options were set, but the port number chosen was invalid or unavailable.</li>
<li><code>13</code> <strong>Unsettled Top-Level Await</strong>: <code>await</code> was used outside of a function
in the top-level code, but the passed <code>Promise</code> never settled.</li>
<li><code>14</code> <strong>Snapshot Failure</strong>: Node.js was started to build a V8 startup
snapshot and it failed because certain requirements of the state of
the application were not met.</li>
<li><code>>128</code> <strong>Signal Exits</strong>: If Node.js receives a fatal signal such as
<code>SIGKILL</code> or <code>SIGHUP</code>, then its exit code will be <code>128</code> plus the
value of the signal code. This is a standard POSIX practice, since
exit codes are defined to be 7-bit integers, and signal exits set
the high-order bit, and then contain the value of the signal code.
For example, signal <code>SIGABRT</code> has value <code>6</code>, so the expected exit
code will be <code>128</code> + <code>6</code>, or <code>134</code>.</li>
</ul></section>
<!-- API END -->
</div>
</div>
</div>
</body>
</html>
|