Let's start building our register and broadcast node endpoint. The function of this endpoint will be to register the new node with itself and then broadcast the new node to all the other nodes that are already present in the network. So, let's get started with building the endpoint:
- From the preceding sections, in the dev/networkNode.js file, we already have the following code:
app.post('/register-and-broadcast-node', function(req, res) {
const newNodeUrl = req.body.newNodeUrl;
Here, we defined a variable called newNodeUrl, and this newNodeUrl data will be passed onto the request body, similar to how we have transaction data being passed into the transaction endpoint. With access to the newNodeUrl, the first thing that we want to do is register the node with the node's register-and-broadcast...