Skip to content

Instantly share code, notes, and snippets.

View PedroGutierrezStratio's full-sized avatar

Pedro Gutiérrez PedroGutierrezStratio

View GitHub Profile
@PedroGutierrezStratio
PedroGutierrezStratio / webSocketServer.js
Last active April 3, 2022 15:41
Node.js (WebSocket with MongoDB updates)
var http = require('http');
var MongoClient = require('mongodb').MongoClient;
var server = require('websocket').server;
startMongoDBConnection();
function startMongoDBConnection(){
MongoClient.connect('mongodb://localhost:27017/sparta', function(err, db) {
startWebSocketServer(db);
});
@PedroGutierrezStratio
PedroGutierrezStratio / index.html
Last active August 16, 2020 03:34
Drawing the MongoDB's data with Chart.js through WebSockets.
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<div style="margin: 20px;display: block;">
<canvas style="width: 600px; height: 300px" id="chart"></canvas>
</div>
<script src="https://cdnjs.cloudflare.com/ajax/libs/Chart.js/1.0.2/Chart.js"></script>
<script>
var ws = new WebSocket('ws://127.0.0.1:8008/');