Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
mongoClient is not connecting to server, it cannot find my silentSight collection. I have created that in the terminal. MY question is how to get that collection visible to my website
<!doctype html>
<html>
<head>
<title>Silent Sight</title>
<link href="Style/main.css" rel="stylesheet" type="text/css"/>
</head>
<h1>
Silent Sight
</h1>
<body id:"mainBody">
<p>
This is a website where you can find all the most up to date sales and bids in the bitcoin market.
</p>
<p>
Click on a tab to get information from different Bitcoin Sites
</p>
<table id="bitStampTable" style="width:100%" border="1">
</table>
<h2>Bids</h2>
<div id="bids_placeholder">waiting for orders...</div>
<h2>Asks</h2>
<div id="asks_placeholder">waiting for orders...</div>
<script src="https://cdn.socket.io/socket.io-1.3.6.js"></script>
<script src="http://localhost:3000/socket.io/socket.io.js"></script>
<script src="wait.js"></script>
<script scr="server.js"></script>
<script>
function tableCreate(order_holder){
var body = document.getElementById('mainBody');
var tbl = document.getElementById('bitStampTable');
var tbdy = document.createElement('tbody');
for (var i in order_holder.bids){
var tr = document.createElement('tr');
var td = document.createElement('td');
var td2 = document.createElement('td');
//var tdInfo = document
td.appendChild(document.createTextNode(order_holder.bids[i]))
td2.appendChild(document.createTextNode(order_holder.asks[i]))
//i == 1 && j == 1 ? td.setAttribute('rowSpan', '2') : null;
tr.appendChild(td)
tr.appendChild(td2)
tbdy.appendChild(tr);
}
console.log(tbl);
tbl.appendChild(tbdy);
tbl.parentNode.replaceChild(tbdy,tbdy);
tbl.innerHTML = tbdy.innerHTML;
}
var bids_placeholder = document.getElementById("bids_placeholder")
var asks_placeholder = document.getElementById("asks_placeholder")
var socket = io.connect('http://localhost:3000');
socket.on('dataOrderBook', function (order_holder) {
console.log(order_holder);
console.log(Date());
socket.emit('dataOrderBook', order_holder);
//document.getElementById("bids_placeholder").innerHTML = order_holder.bids;
//document.getElementById("asks_placeholder").innerHTML = order_holder.asks;
tableCreate(order_holder);
});
</script>
</script>
</body>
</html>
require('waitjs');
var MongoClient = require('mongodb').MongoClient;
var assert = require('assert');
var express = require('express')
var app = express()
var got = require('got');
var server = require('http').createServer(app)
var io = require('socket.io').listen(server);
var order_book;
//var order_table = {};
server.listen(3000);
var url = 'mongodb://localhost:3000/silentSight'
MongoClient.connect(url, function(err, db){
assert.equal(null, err);
console.log("Connected correctly to server.");
db.close();
});
app.get('/', function(req, res){
res.sendFile(__dirname + '/index.html');
})
got('https://www.bitstamp.net/api/order_book/', function(error, data, res) {
order_book = data;
console.log(order_book);
})
io.on('connection', function (socket) {
pullData(socket);
socket.on('dataOrderBook', function(order_book) {
console.log(order_book);
});
});
function pullData (socket) {
repeat(1500, function(){
console.log(Date());
got('https://www.bitstamp.net/api/order_book/', function(error, data, res) {
console.log(Date());
order_book = JSON.parse(data);
var order_bids = order_book.bids;
var order_asks = order_book.asks;
var order_holder = {}
order_holder.bids = order_bids;
order_holder.asks = order_asks;
socket.emit('dataOrderBook', order_holder);
//order_table.bids = order_holder.bids;
//order_table.asks = order_holder.asks;
});
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment