The Node.js® Website
at main 2.5 kB view raw
1import { DIST_URL } from '@/next.constants.mjs'; 2import type { UserOS } from '@/types/userOS'; 3 4export const getNodeDownloadUrl = ( 5 versionWithPrefix: string, 6 os: UserOS, 7 bitness: string | number, 8 kind: 'installer' | 'binary' | 'source' = 'installer' 9): string => { 10 const baseURL = `${DIST_URL}${versionWithPrefix}`; 11 12 if (kind === 'source') { 13 return `${baseURL}/node-${versionWithPrefix}.tar.gz`; 14 } 15 16 switch (os) { 17 case 'MAC': 18 // Prepares a downloadable Node.js installer link for the x64, ARM64 platforms 19 if (kind === 'installer') { 20 return `${baseURL}/node-${versionWithPrefix}.pkg`; 21 } 22 23 // Prepares a downloadable Node.js link for the ARM64 platform 24 if (typeof bitness === 'string') { 25 return `${baseURL}/node-${versionWithPrefix}-darwin-${bitness}.tar.gz`; 26 } 27 28 // Prepares a downloadable Node.js link for the x64 platform. 29 // Since the x86 platform is not officially supported, returns the x64 30 // link as the default value. 31 return `${baseURL}/node-${versionWithPrefix}-darwin-x64.tar.gz`; 32 case 'WIN': { 33 if (kind === 'installer') { 34 // Prepares a downloadable Node.js installer link for the ARM platforms 35 if (typeof bitness === 'string') { 36 return `${baseURL}/node-${versionWithPrefix}-${bitness}.msi`; 37 } 38 39 // Prepares a downloadable Node.js installer link for the x64 and x86 platforms 40 return `${baseURL}/node-${versionWithPrefix}-x${bitness}.msi`; 41 } 42 43 // Prepares a downloadable Node.js link for the ARM64 platform 44 if (typeof bitness === 'string') { 45 return `${baseURL}/node-${versionWithPrefix}-win-${bitness}.zip`; 46 } 47 48 // Prepares a downloadable Node.js link for the x64 and x86 platforms 49 return `${baseURL}/node-${versionWithPrefix}-win-x${bitness}.zip`; 50 } 51 case 'LINUX': 52 // Prepares a downloadable Node.js link for the ARM platforms such as 53 // ARMv7 and ARMv8 54 if (typeof bitness === 'string') { 55 return `${baseURL}/node-${versionWithPrefix}-linux-${bitness}.tar.xz`; 56 } 57 58 // Prepares a downloadable Node.js link for the x64 platform. 59 // Since the x86 platform is not officially supported, returns the x64 60 // link as the default value. 61 return `${baseURL}/node-${versionWithPrefix}-linux-x64.tar.xz`; 62 default: 63 // Prepares a downloadable Node.js source code link 64 return `${baseURL}/node-${versionWithPrefix}.tar.gz`; 65 } 66};