Skip to content

Instantly share code, notes, and snippets.

@dalelane
dalelane / nodejs_db_with_restapi.js
Created June 15, 2014 21:09
Node.js, Express, and SQLite to wrap a REST API around an SQL database
var sqlite3 = require('sqlite3').verbose();
var db = new sqlite3.Database('data/demodb02');
db.serialize(function() {
db.run("CREATE TABLE IF NOT EXISTS counts (key TEXT, value INTEGER)");
db.run("INSERT INTO counts (key, value) VALUES (?, ?)", "counter", 0);
});
@sahat
sahat / client.js
Last active February 23, 2022 17:09
Calculate client-server latency using socket.io
var socket = io.connect('http://localhost');
var startTime;
setInterval(function() {
startTime = Date.now();
socket.emit('ping');
}, 2000);
socket.on('pong', function() {
latency = Date.now() - startTime;