Skip to content

Instantly share code, notes, and snippets.

@lmammino
Created August 3, 2021 19:03
Show Gist options
  • Save lmammino/6b5eb49a2ed2658b7372d56a8f625dfc to your computer and use it in GitHub Desktop.
Save lmammino/6b5eb49a2ed2658b7372d56a8f625dfc to your computer and use it in GitHub Desktop.
Get your public IP in TypeScript
import { getMyPublicIp } from './utils.ts'
getMyPublicIp
.then(console.log)
.catch(console.error)
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