socket.on("newPrivateMessage", function(data) { if (data.img) { var img = new Image(); img.src = 'data:image/jpeg;base64,' + data.img; // Do whatever you want with your image. } });