Extending our application

The first step in enhancing our application is to have it deliver HTML instead of plain text.
HTML is the markup language of the web, which is used to give a web page its structure. In essence, it's just a bunch of tags that give meaning to the text.

For example, the current output from the temperature API is 26°C. Although it gives us the information we need, it would be more meaningful to highlight the actual value more than the unit. An output of 26°C looks better than our plain text version.

Let's translate this into HTML. We have the strong tag, which is used to give emphasis to the text by making it thicker than usual.

The standard format of HTML tags is as follows:

    <tag>text</tag>

Here, we replace tag with the name of our tag. If we wanted to make only the value bolder, we would write this:

    <strong>26</strong> °C

The good news is that our node server can already deliver this. When plain text contains HTML tags, almost all popular browsers automatically treat it as HTML.

We will then modify our temperature API to highlight the value of the temperature:

    app.get('/temperature', function (req, res) {
res.send('<strong>' +
getCachedSensorReadings.getTemperature().toFixed(1) +
'</strong>' + '°C')
})

Try hitting this URL in your browser, and you should see the temperature value in bold.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.133.12.172