-
Notifications
You must be signed in to change notification settings - Fork 448
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Updating instructions in examples/transports tut #1200
Conversation
2022-05-03 conversation: there are two things in this PR:
We don't want the move back to CJS given we are making js-libp2p ESM-only. We do want the new/helpful content. @walkerlj0 : if you are wanting to contribute more here, please reduce to #2 only. Otherwise, it will get picked up once the EMS-only js-libp2p is released. |
@walkerlj0 libp2p 0.37.0 has finally been released with ESM-only exports. Can you try to make the examples run against the latest version? |
Now that we have a function to create our own libp2p node, let's create a node with it. Inside of the createNode() async function, before the `return node` and after the `await node.start() ` statement, add in some logging: | ||
|
||
```JavaScript | ||
const createNode = async () => { | ||
... | ||
await node.start() | ||
|
||
console.log('node has started (true/false):', node.isStarted()) | ||
console.log('listening on:') | ||
node.multiaddrs.forEach((ma) => console.log(`${ma.toString()}/p2p/${node.peerId.toB58String()}`)) | ||
|
||
return node | ||
} | ||
``` | ||
|
||
Now, you want to call the `createNode()` function, and you can also add in error handling: | ||
|
||
```JavaScript | ||
const node = await createNode() | ||
|
||
// At this point the node has started | ||
console.log('node has started (true/false):', node.isStarted()) | ||
// And we can print the now listening addresses. | ||
// If you are familiar with TCP, you might have noticed | ||
// that we specified the node to listen in 0.0.0.0 and port | ||
// 0, which means "listen in any network interface and pick | ||
// a port for me | ||
console.log('listening on:') | ||
node.multiaddrs.forEach((ma) => console.log(`${ma.toString()}/p2p/${node.peerId.toB58String()}`)) | ||
createNode().catch(err => { | ||
console.error(err) | ||
process.exit(1) | ||
}) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you revert the changes other than this? We want to keep examples using the latest versions of libp2p dependencies, using ESM imports, etc.
@walkerlj0: are you able to incorporate the feedback so the PR can be merged? |
I will try and run it in the next coupld days, so sorry, been swamped! |
@walkerlj0 we converted it to draft state until you are ready. |
@mpetrunic tried running transports/1.js and got this error, advice on how to troubleshoot? **Note I did fetch upstream from libp2p:master
|
If you fetched latest master, do Gonna close this PR as examples work just fine for me locally! |
Updated part 1 (1.js)