Ethereum: Store console.log result into array every 3 second

I can provide yu wth an example article that demonstrateds how to achieve that with the help of JavaScript, HTML and CSS.

Ethereum: Result of the story’s log in an array 3 seconds

In this example, we will give a node.js as server language and create a simple api to get api to get Binance’s Bitcoin Prices. We are also to WebSockets to press the clickdates every 3 seconds.

Server Side (Node.js)

`javascript

CONST Express = Requirement (‘Express’);

CONST App = Express ();

Const Websocket = Requirement (‘WS’);

CONST WSS ​​= New Websocket.Server ({Port: 8080});

app.get (‘/api/btc/price’, (req, res) => {{

const Socket = wss.accept (req, res);

const prices = [];

Socket.on (‘message’, (data) => {>

If (json.parse (data) .symbol === ‘btc’) {

Prices.Push (JSON.PARSE (data) .latstprice);

Console.log (Last price: $ {prices [prices.length - 1]});

// Press the assist

Socket.send ({symbol: ‘btc’, the most of prices: prices [price.length – 1])));

}

});

Socket.on (‘Close’, () => {

ws.close ();

});

});

App.listen (8080, () => {

Console.log (“Listening to server on port 8080”);

});

`

Client Party (HTML and JavaScript)

Ethereum: Store console.log result into array every 3 second

`html

Binance prices tracking

#Price-Container {

Font size: 24px;

Font weight: bold;

Margin-Dono: 20px;

}

Binance prices tracking

< DIV>

Explanation

  • We create a sever Express.js wholsens to the port 8080 and websocket lines.

  • When received, it analyzes JSON data and stories the “Prices” array.

  • At each incoming message, we check that the symbol is “BTC” If so, we analyze the Data and run the new price

  • We also register the last place the console for the purposes of errors.

  • When connecting WebSocket closes, we update theerface with a message, that are the ones.

To refresh the page you want the last year, just recharge the “Recharge Price” but the right of container. The server will automatically refresh and press newsss.

ethereum convert value

Leave a comment

Your email address will not be published. Required fields are marked *