~2 min read • Updated Dec 30, 2025
1. Introduction
Punycode is a character encoding scheme that converts Unicode strings into ASCII-only strings. It is primarily used for domain names containing non-ASCII characters, ensuring compatibility with DNS and URL systems.
const punycode = require('node:punycode');
2. Core Methods
punycode.encode(string): Converts Unicode strings to Punycode.punycode.decode(string): Converts Punycode strings back to Unicode.
punycode.encode('mañana'); // 'maana-pta'
punycode.decode('maana-pta'); // 'mañana'
3. Domain Conversion
punycode.toASCII(domain): Converts Unicode domain names to Punycode.punycode.toUnicode(domain): Converts Punycode domain names back to Unicode.
punycode.toASCII('mañana.com'); // 'xn--maana-pta.com'
punycode.toUnicode('xn--maana-pta.com'); // 'mañana.com'
4. UCS2 Utilities
punycode.ucs2.decode(string): Returns an array of Unicode code points.punycode.ucs2.encode(codePoints): Builds a string from an array of code points.
punycode.ucs2.decode('abc'); // [0x61, 0x62, 0x63]
punycode.ucs2.encode([0x61, 0x62, 0x63]); // 'abc'
5. Version
punycode.version: Returns the current Punycode.js version string.
6. Deprecation and Alternatives
The punycode module is deprecated and will be removed in future Node.js releases. Recommended alternatives include:
- The standalone Punycode.js library.
url.domainToASCIIor the WHATWG URL API for domain encoding.
Conclusion
The punycode module provided a convenient way to handle internationalized domain names in Node.js. However, with its deprecation, developers should adopt modern APIs or external libraries to ensure compatibility and future-proof applications.
Written & researched by Dr. Shahin Siami