Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import { Node, NetworkHub } from 'smoke-node'
- async function main() {
- const node_a = new Node({ hub: new NetworkHub('ws://tachy0n.com:5001/') })
- const node_b = new Node({ hub: new NetworkHub('ws://tachy0n.com:5001/') })
- const node_a_address = await node_a.address()
- // get the address of this node on the virtual network
- console.log('node_a', await node_a.address())
- console.log('node_b', await node_a.address())
- console.log('node_a_config', JSON.stringify(await node_a.hub.configuration(), null, 2))
- console.log('node_b_config', JSON.stringify(await node_a.hub.configuration(), null, 2))
- // create a simple rest server.
- const server = node_a.rest.createServer()
- server.get('/', (req, res) => {
- res.send('response from node_a')
- })
- server.listen(80)
- // fetch it
- const data = await node_b.rest.fetch(`rest://${node_a_address}`).then(res => res.text())
- console.log(data)
- }
- main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement