Building the /block-explorer endpoint

Let's build an endpoint that will retrieve the block-explorer file for us:

  1. Go to the dev/networkNode.js file, and in here, create a new endpoint that will send this file to us. Define the endpoint as follows: 
app.get('/block-explorer', function(req, res) {});
  1. Now, inside of this endpoint, all we want to do is send back the index.html file to whoever called this endpoint:
app.get('/block-explorer', function(req, res) {    res.sendFile('./block-explorer/index.html', { root: __dirname });});

You must have observed in the previous sections that we usually use res.json, which is a way to send JSON data. However, in this endpoint, we want to send the whole file, so we'll use the res.sendFile method instead. ...

Get Learn Blockchain Programming with JavaScript now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.