HomeHow to format output of international phone number with JavaScript

How to format output of international phone number with JavaScript

Published: 11/1/2025

Long story short: if you need to format an international phone number with country code, area code brackets and all the spacing, use libphonenumber-js.

Install package with npm i --save libphonenumber-js

Option 1:

const phone = parsePhoneNumberFromString('+14155552671');
console.log(phone.formatInternational()); // "+1 415 555 2671"

Option 2:

const phone = parsePhoneNumberFromString('+14155552671');
console.log(`+${phone.countryCallingCode} ${phone.formatNational()}`); // "+1 (415) 555-2671"

About Code with Node.js

This is a personal blog and reference point of a Node.js developer.

I write and explain how different Node and JavaScript aspects work, as well as research popular and cool packages, and of course fail time to time.