Created
August 3, 2021 19:03
-
-
Save lmammino/6b5eb49a2ed2658b7372d56a8f625dfc to your computer and use it in GitHub Desktop.
Get your public IP in TypeScript
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { getMyPublicIp } from './utils.ts' | |
getMyPublicIp | |
.then(console.log) | |
.catch(console.error) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import * as https from 'https' | |
export function getMyPublicIp(): Promise<String> { | |
return new Promise((resolve, reject) => { | |
https.get('https://checkip.amazonaws.com/', (res) => { | |
res.on('data', (d: Buffer) => { | |
resolve(d.toString()) | |
}) | |
res.on('error', reject) | |
}) | |
}) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment