Ex No: 8 WEB CLIENT USING NODE.JS
Aim: To implement a server that reads and sends a HTML page using node.js.
Procedure
Step1: Install Node Package Manager (npm) in the system.
Step2: Initialize Node.js using "npm init -y" in the terminal.
Step3: Create a file client.js” to implement the server.
Step4: Include "http" module to request JSON data from the server "dummyjson.com" and read it.
Step6: Quotes from the JSON data is displayed in the Console.
Step7: Run the code using "node client.js".
Source Code

server.js


const https = require('https');

const options = {
  host: 'dummyjson.com',
  path: '/quotes',
  method: 'GET',
  headers: {
    'Accept': 'application/json',
    'Content-Type': 'application/json; charset=UTF-8'
  }
};//http Options

const client = https.request(options, (res) => {
  if (res.statusCode !== 200) {
    console.error(`Did not get an OK from the server. Code: ${res.statusCode}`);
    res.resume();
    return;
  }//End of if

  let data = '';

  res.on('data', (packet) => {
    data += packet;
  });//End of on data receive from server.

  var QuotesJSON;
  res.on('close', () => {
    console.log('Quotes Received');
    QuotesJSON = JSON.parse(data);
    for(var i=0;i<QuotesJSON.quotes.length;i++)
    {
        var QuotesData = QuotesJSON.quotes[i];
        console.log(QuotesData.quote+"\n By Author: "+ QuotesData.author+"\n");
    }
  });//End of server connection close

});//End of Client Request

client.end();

client.on('error', (err) => {
  console.error(`Encountered an error trying to make a request: ${err.message}`);
});

Result: Thus node.js client is implemented to request JSON data from the server and display it.