Skip to content

Instantly share code, notes, and snippets.

@bohack
Created February 22, 2017 02:54
Show Gist options
  • Save bohack/9e22677fa3d08427be9e90362a220c74 to your computer and use it in GitHub Desktop.
Save bohack/9e22677fa3d08427be9e90362a220c74 to your computer and use it in GitHub Desktop.
Node.JS Server which reads a SQLITE database and outputs HTML
var sqlite3 = require('sqlite3').verbose();
var file = "mydb.db";
var db = new sqlite3.Database(file);
db.all("SELECT rowid AS id, info FROM user_info", function(err, rows) {
var http = require("http");
var server = http.createServer(function(request, response) {
//var now = new Date();
//console.log('Request at ' + now);
response.writeHead(200, {"Content-Type": "text/html"});
response.write("<!DOCTYPE html>");
response.write("<html>");
response.write("<head>");
response.write("<title>Helpdesk Tickets Open</title>");
response.write("</head>");
response.write("<body>");
rows.forEach(function (row) {
response.write(row.id + " - " + row.info + "<br>");
})
response.write("</body>");
response.write("</html>");
response.end();
});
db.close();
server.listen(80);
console.log("Server is listening");
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment