const WebSocket = require('ws') const wss = new WebSocket.Server({ port: 8080 }) const now = () => { return new Date().getTime() } wss.on('connection', (ws) => { ws.on('message', function(data) { var msg=JSON.parse(data) msg.took=now() - msg.start ws.send(JSON.stringify(msg)) }) })