Created
May 6, 2020 16:38
-
-
Save rumkin/51bc6a346b40e6a303d1e1eba1f38199 to your computer and use it in GitHub Desktop.
Utils for LibP2P example
This file contains 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
// Usage is node exec.js app.js | |
// app.js should export default function | |
import path from 'path' | |
async function execute(filename) { | |
const {default: main} = await import( | |
path.resolve(filename) | |
) | |
return main({ | |
argv: process.argv.slice(3), | |
parsedArgv: process.argv.slice(0, 3), | |
}) | |
} | |
execute(process.argv[2]) | |
.catch(err => { | |
console.error(err) | |
return 1 | |
}) | |
.then((code = 0) => process.exit(code)) |
This file contains 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 PeerId from 'peer-id' | |
PeerId.create() | |
async function main() { | |
const peer = await PeerId.create({ | |
keyType: 'secp256k1', | |
}) | |
console.log(JSON.stringify( | |
peer.toJSON(), | |
null, | |
4 | |
)) | |
} | |
main() | |
.catch(err => { | |
console.error(err) | |
return 1 | |
}) | |
.then((code = 0) => process.exit(code)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment