export function configuration(env) { const raw = env.PORT ?? '3000'; if (!/^[0-9]+$/.test(raw)) throw new Error('Invalid port'); const port = Number(raw); if (!Number.isInteger(port) || port < 1024 || port > 65535) throw new Error('Invalid port'); const mode = env.NODE_ENV ?? 'development'; if (!['development', 'test', 'production'].includes(mode)) throw new Error('Invalid mode'); return { port, mode }; } console.log(JSON.stringify(configuration({ PORT: '3100', NODE_ENV: 'test' }))); try { configuration({ PORT: '3100oops' }); } catch (error) { console.log(error.message); }